annotate src/projectm-1.0/main.cxx @ 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 c733dd93af62
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3040
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /*
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 projectM v1.01 - xmms-projectm.sourceforge.net
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3 --------------------------------------------------
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5 Lead Developers: Carmelo Piccione (carmelo.piccione@gmail.com) &
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 Peter Sperl (peter@sperl.com)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8 We have also been advised by some professors at CMU, namely Roger B. Dannenberg.
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9 http://www-2.cs.cmu.edu/~rbd/
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 The inspiration for this program was Milkdrop by Ryan Geiss. Obviously.
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
12
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13 This code is distributed under the GPL.
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 THANKS FOR THE CODE!!!
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 -------------------------------------------------
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18 The base for this program was andy@nobugs.org's XMMS plugin tutorial
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 http://www.xmms.org/docs/vis-plugin.html
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 We used some FFT code by Takuya OOURA instead of XMMS' built-in fft code
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 fftsg.c - http://momonga.t.u-tokyo.ac.jp/~ooura/fft.html
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 and some beat detection code was inspired by Frederic Patin @
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 www.gamedev.net/reference/programming/features/beatdetection/
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 #include <stdio.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30 #include <string.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 #include <string>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32 #include <stdlib.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 #include <unistd.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 #include <fcntl.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 #include <SDL/SDL.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36 #include <SDL/SDL_thread.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 extern "C" {
3203
f5456241bff9 changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3044
diff changeset
39 #include <audlegacy/util.h>
f5456241bff9 changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3044
diff changeset
40 #include <audlegacy/plugin.h>
f5456241bff9 changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3044
diff changeset
41 #include <audlegacy/auddrct.h>
3040
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 #include <math.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 #include "ConfigFile.h"
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 #include <libprojectM/projectM.hpp>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49 #include "sdltoprojectM.h"
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50 #include "video_init.h"
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 #include <GL/gl.h>
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 #define CONFIG_FILE "/share/projectM/config.inp"
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 // Forward declarations
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 extern "C" void projectM_xmms_init(void);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 extern "C" void projectM_cleanup(void);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 extern "C" void projectM_about(void);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 extern "C" void projectM_configure(void);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 extern "C" void projectM_playback_start(void);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 extern "C" void projectM_playback_stop(void);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62 extern "C" void projectM_render_pcm(gint16 pcm_data[2][512]);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 extern "C" void projectM_render_freq(gint16 pcm_data[2][256]);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 extern "C" int worker_func(void*);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 std::string read_config();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 void saveSnapshotToFile();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68 extern "C" VisPlugin projectM_vtable;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 //extern preset_t * active_preset;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 //FILE * debugFile = fopen("./dwrite-dump", "wb");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 // Our worker thread
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75 SDL_Thread *worker_thread = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 SDL_sem *sem = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77 SDL_Event event;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 SDL_Surface *screen;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 projectM * globalPM = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 int maxsamples=512;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 int texsize=512;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 int gx=32,gy=24;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88 int wvw=400,wvh=400;
3044
c733dd93af62 Queued projectm fixes.
William Pitcock <nenolod@atheme.org>
parents: 3040
diff changeset
89 int fvw=1680,fvh=1050;
c733dd93af62 Queued projectm fixes.
William Pitcock <nenolod@atheme.org>
parents: 3040
diff changeset
90 int fps=35, fullscreen=1;
3040
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 // char *title;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94 gint disable_projectm(void *something) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 projectM_vtable.disable_plugin(&projectM_vtable);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 return 0;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 Uint32 get_xmms_title(Uint32 something, void *somethingelse) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100 static char check_title = 1;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 static int last_pos;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 static char *last_title = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103 int pos;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104 char *title = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106 //Nice optimization, but we want the title no matter what so I can display it when the song changes
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 #if 0
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108 if(!(globalPM->showtitle%2)) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 /* Repeat less often when not showing title */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110 return 1000;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 #endif
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
114 pos = audacious_drct_pl_get_pos();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
115 /* Only check every 1 second for title change, otherwise check pos */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116 if(check_title || pos != last_pos) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 title = audacious_drct_pl_get_title(pos);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118 if(title && (!last_title || strcmp(last_title,title))) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119 //globalPM->renderer->title = title;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120 //globalPM->renderer->drawtitle = 1;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 std::string titlepp(title);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 globalPM->projectM_setTitle(titlepp);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 g_free(last_title);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 last_title = title;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126 } else if(title && last_title != title) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127 /* New copy of last title */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128 g_free(title);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 check_title = !check_title;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132 last_pos = pos;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 /* Repeat every 500ms */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 return 500;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 int capture = 0;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 int worker_func(void*)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 // char projectM_data[1024];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 SDL_TimerID title_timer = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143 std::string config_file;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
144 config_file = read_config();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 ConfigFile config(config_file);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147 int wvw = config.read<int>( "Window Width", 512 );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 int wvh = config.read<int>( "Window Height", 512 );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
150 int fullscreen = 0;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 if (config.read("Fullscreen", true)) fullscreen = 1;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
152 else fullscreen = 0;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
153
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
154 init_display(wvw,wvh,&fvw,&fvh,fullscreen);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155 SDL_WM_SetCaption("projectM v1.00", "projectM v1.00");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
157 /** Initialise projectM */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
158
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159 globalPM = new projectM(config_file);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
160 SDL_SemPost(sem);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
161 title_timer = SDL_AddTimer(500, get_xmms_title, NULL);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
162 /** Initialise the thread */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
163 // SDL_SemTryWait(sem);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
164 while ( SDL_SemValue(sem)==1 ) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 projectMEvent evt;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
166 projectMKeycode key;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
167 projectMModifier mod;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
168
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
169 /** Process SDL events */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
170 SDL_Event event;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
171 while ( SDL_PollEvent( &event ) ) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
172 /** Translate into projectM codes and process */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
173 evt = sdl2pmEvent( event );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
174
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
175 key = sdl2pmKeycode( event.key.keysym.sym );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
176 mod = sdl2pmModifier( event.key.keysym.mod );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
178 if ( evt == PROJECTM_KEYDOWN ) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
179
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
180 if(key == PROJECTM_K_c)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
181 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
182 //SDL_SaveBMP(screen, "/home/pete/1.bmp");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
183 saveSnapshotToFile();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
184 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
185 if(key == PROJECTM_K_v)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
186 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
187 // capture++;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
188 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
189 if(key == PROJECTM_K_f)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
190 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
191
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
192
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
193 int w, h;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
194 if (fullscreen == 0) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
195 w = fvw;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
196 h = fvh;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
197 fullscreen = 1;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
198 } else {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
199 w = wvw;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
200 h = wvh;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 fullscreen = 0;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
203
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
204 resize_display(w, h, fullscreen);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
205 globalPM->projectM_resetGL( w, h );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
206 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
207 else globalPM->key_handler(evt,key,mod);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
208
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
209 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210 else if ( evt == PROJECTM_VIDEORESIZE )
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
211 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
212
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
213
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 wvw=event.resize.w;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216 wvh=event.resize.h;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
218
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 resize_display(wvw,wvh,fullscreen);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220 globalPM->projectM_resetGL( wvw, wvh );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
221
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223 else if ( evt == PROJECTM_VIDEOQUIT ) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
225 (void) g_idle_add ((GSourceFunc) disable_projectm, NULL);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 /** Add the waveform data */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
231
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232 /** Render the new frame */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 // strcpy(title,xmms_remote_get_playlist_title(projectM_vtable.xmms_session, xmms_remote_get_playlist_pos(projectM_vtable.xmms_session)));
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
234
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
235 //printf("%s\n",title);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
236 // strcpy(globalPM->title,title);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 globalPM->renderFrame();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
241
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
242 SDL_GL_SwapBuffers();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 if (capture % 2 == 1) saveSnapshotToFile();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245 // SDL_SemPost(sem);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
246 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248 if(title_timer)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 SDL_RemoveTimer(title_timer);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250 delete globalPM;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
252
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
253 return 0;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
254 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
255
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256 extern "C" void projectM_xmms_init(void)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 /* First, initialize SDL's video subsystem. */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260 // std::cerr << "sdl init begin" << std::endl;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261 if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
262 /* Failed, exit. */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263 fprintf( stderr, "Video initialization failed: %s\n",
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264 SDL_GetError( ) );
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265 //projectM_vtable.disable_plugin (&projectM_vtable);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 return;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 sem = SDL_CreateSemaphore(0);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270 // printf("projectM plugin: Initializing\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272 SDL_EnableUNICODE(1);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274 worker_thread = SDL_CreateThread ( *worker_func, NULL);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
276 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
277
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
278
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
280 extern "C" void projectM_cleanup(void)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
281 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 if(!sem) return;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284 SDL_SemWait(sem);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285 if(worker_thread) SDL_WaitThread(worker_thread, NULL);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286 // SDL_KillThread(worker_thread);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287 //printf("killed thread\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289 SDL_DestroySemaphore(sem);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290 //printf("Destroy Mutex\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291 SDL_Quit();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
292
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
293 sem = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294 worker_thread = NULL;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296 // printf("projectM plugin: Cleanup completed\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
297 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
298 extern "C" void projectM_about(void)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
299 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
300 printf("projectM plugin: About\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
301 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
302 extern "C" void projectM_configure(void)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
303 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
304 printf("projectM plugin: Configure\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
305 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
306 extern "C" void projectM_playback_start(void)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
307 {//thread_control = GO;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
308 printf("projectM plugin: Playback starting\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
309 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
310 extern "C" void projectM_playback_stop(void)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
311 {//thread_control = STOP;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
312 printf("projectM plugin: Playback stopping\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
313 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
314 extern "C" void projectM_render_pcm(gint16 pcm_data[2][512])
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
315 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
316 //SDL_mutexP(mutex); while ( SDL_SemValue(sem)==1 )
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
317 if ( SDL_SemValue(sem)==1 )
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
318 globalPM->pcm()->addPCM16(pcm_data);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
319
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
320 //SDL_mutexV(mutex);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
321
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
322 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
323
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
324 extern "C" void projectM_render_freq(gint16 freq_data[2][256])
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
325 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
326 printf("NO GOOD\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
327 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
328
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
329 std::string read_config()
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
330 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
331
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
332 // int n;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
333
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
334 char num[512];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
335 FILE *in;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
336 FILE *out;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
337
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
338 char* home;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
339 char projectM_home[1024];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
340 char projectM_config[1024];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
341
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
342 strcpy(projectM_config, PROJECTM_PREFIX);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
343 strcpy(projectM_config+strlen(PROJECTM_PREFIX), CONFIG_FILE);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
344 projectM_config[strlen(PROJECTM_PREFIX)+strlen(CONFIG_FILE)]='\0';
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
345 //printf("dir:%s \n",projectM_config);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
346 home=getenv("HOME");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
347 strcpy(projectM_home, home);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
348 strcpy(projectM_home+strlen(home), "/.projectM/config.inp");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
349 projectM_home[strlen(home)+strlen("/.projectM/config.inp")]='\0';
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
350
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
351
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
352 if ((in = fopen(projectM_home, "r")) != 0)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
353 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
354 //printf("reading ~/.projectM/config.inp \n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
355 fclose(in);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
356 return std::string(projectM_home);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
357 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
358 else
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
359 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
360 printf("trying to create ~/.projectM/config.inp \n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
361
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
362 strcpy(projectM_home, home);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
363 strcpy(projectM_home+strlen(home), "/.projectM");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
364 projectM_home[strlen(home)+strlen("/.projectM")]='\0';
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
365 mkdir(projectM_home,0755);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
366
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
367 strcpy(projectM_home, home);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
368 strcpy(projectM_home+strlen(home), "/.projectM/config.inp");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
369 projectM_home[strlen(home)+strlen("/.projectM/config.inp")]='\0';
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
370
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
371 if((out = fopen(projectM_home,"w"))!=0)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
372 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
373
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
374 if ((in = fopen(projectM_config, "r")) != 0)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
375 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
376
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
377 while(fgets(num,80,in)!=NULL)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
378 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
379 fputs(num,out);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
380 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
381 fclose(in);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
382 fclose(out);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
383
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
384
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
385 if ((in = fopen(projectM_home, "r")) != 0)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
386 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
387 printf("created ~/.projectM/config.inp successfully\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
388 fclose(in);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
389 return std::string(projectM_home);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
390 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
391 else{printf("This shouldn't happen, using implementation defualts\n");abort();}
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
392 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
393 else{printf("Cannot find projectM default config, using implementation defaults\n");abort();}
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
394 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
395 else
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
396 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
397 printf("Cannot create ~/.projectM/config.inp, using default config file\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
398 if ((in = fopen(projectM_config, "r")) != 0)
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
399 { printf("Successfully opened default config file\n");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
400 fclose(in);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
401 return std::string(projectM_config);}
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
402 else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n"); abort();}
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
403 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
404
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
405 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
406
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
407 abort();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
408 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
409
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
410 int frame = 1;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
411
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
412
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
413 void saveSnapshotToFile()
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
414 {
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
415 char dumpPath[512];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
416 char Home[512];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
417 //char *home;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
418
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
419 SDL_Surface * bitmap;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
420
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
421 GLint viewport[4];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
422 long bytewidth;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
423 GLint width, height;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
424 long bytes;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
425
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
426 glReadBuffer(GL_FRONT);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
427 glGetIntegerv(GL_VIEWPORT, viewport);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
428
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
429 width = viewport[2];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
430 height = viewport[3];
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
431
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
432 bytewidth = width * 4;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
433 bytewidth = (bytewidth + 3) & ~3;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
434 bytes = bytewidth * height;
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
435
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
436 /*
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
437 glFinish();
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
438 glPixelStorei(GL_PACK_ALIGNMENT, 4);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
439 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
440 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
441 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
442 */
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
443
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
444
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
445 bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,0,0,0,0);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
446 glReadPixels(0, 0, width, height,
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
447 GL_BGRA,
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
448 GL_UNSIGNED_INT_8_8_8_8_REV,
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
449 bitmap->pixels);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
450
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
451 sprintf(dumpPath, "/.projectM/%.8d.bmp", frame++);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
452 // home=getenv("HOME");
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
453 strcpy(Home, getenv("HOME"));
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
454 strcpy(Home+strlen(Home), dumpPath);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
455 Home[strlen(Home)]='\0';
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
456 SDL_SaveBMP(bitmap, Home);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
457
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
458 SDL_FreeSurface(bitmap);
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
459
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
460
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
461 }
f13b61c91ada go back to the SDL version
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
462