116
|
1 /* Iris - visualization plugin for XMMS
|
|
2 * Copyright (C) 2000-2002 Cédric DELFOSSE (cdelfosse@free.fr)
|
|
3 *
|
|
4 * This program is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
17 */
|
|
18
|
|
19 /* New Theme created by Ron Lockwood-Childs
|
|
20 * Looks best when alpha blending is OFF
|
|
21 */
|
|
22
|
|
23 /* $Id: theme_float.c,v 1.1 2002/10/27 19:21:06 cedric Exp $ */
|
|
24
|
|
25 #include <stdlib.h>
|
|
26 #include <stdio.h>
|
|
27 #include <string.h>
|
|
28 #include <math.h>
|
|
29 #include <time.h>
|
|
30 #include <GL/gl.h>
|
|
31 #include <audacious/configdb.h>
|
|
32 #include "iris.h"
|
|
33
|
|
34 #define HISTORY_SIZE 16
|
|
35 #define HALF_BOX 0.15
|
|
36 #define HALF_BOX_Y (HALF_BOX * 2)
|
|
37 #define FAR_LEFT -3.0
|
|
38 #define FAR_BACK -3.0
|
|
39 #define BOTTOM -2.6
|
|
40
|
|
41
|
|
42 typedef struct
|
|
43 {
|
|
44 GLfloat xc;
|
|
45 GLfloat yc;
|
|
46 GLfloat zc;
|
|
47 } triple;
|
|
48
|
|
49 static struct
|
|
50 {
|
|
51 int wave_speed;
|
|
52 gfloat num_blocks;
|
|
53 }
|
|
54 conf_private, conf_private_new;
|
|
55
|
|
56 static config_theme conf = {
|
|
57 NULL,
|
|
58 &conf_private
|
|
59 };
|
|
60
|
|
61 static config_theme conf_new = {
|
|
62 NULL,
|
|
63 &conf_private_new
|
|
64 };
|
|
65
|
|
66
|
|
67 static GLfloat get_x_angle (void);
|
|
68 static void draw_one_frame (gboolean);
|
|
69 static gfloat speed_to_phase(int speed);
|
|
70 static void config_read (ConfigDb *, char *);
|
|
71 static void config_write (ConfigDb *, char *);
|
|
72 static void config_default (void);
|
|
73 static void config_create (GtkWidget *);
|
|
74
|
|
75
|
|
76 static char float_numblocks[] = "float_numblocks";
|
|
77 static char float_wavespeed[] = "float_wavespeed";
|
|
78
|
|
79
|
|
80 iris_theme theme_float = {
|
|
81 "Floaters",
|
|
82 "A spectrum of floating blocks (alpha blend off for best effect)",
|
|
83 "Ron Lockwood-Childs",
|
|
84 "float",
|
|
85 &conf,
|
|
86 &conf_new,
|
|
87 sizeof (conf_private),
|
|
88 config_read,
|
|
89 config_write,
|
|
90 config_default,
|
|
91 config_create,
|
|
92 NULL,
|
|
93 NULL,
|
|
94 NULL,
|
|
95 get_x_angle,
|
|
96 draw_one_frame,
|
|
97 };
|
|
98
|
|
99 static GLfloat data2[NUM_BANDS][HISTORY_SIZE]; // previous freq band data
|
|
100 static GLfloat phase[HISTORY_SIZE]; // previous angle data
|
|
101
|
|
102 static GLfloat
|
|
103 get_x_angle ()
|
|
104 {
|
|
105 return (10.0 + (int) (80.0 * rand () / (RAND_MAX + 1.0)));
|
|
106 }
|
|
107
|
|
108 static void
|
|
109 draw_one_frame (gboolean beat)
|
|
110 {
|
|
111 int t1, t2; // loop vars
|
|
112 GLfloat red, green, blue;
|
|
113 GLfloat y_color = 0.0;
|
|
114 triple ulf, urf, llf, lrf, ulb, urb, llb, lrb;
|
|
115 GLfloat basis[NUM_BANDS];
|
|
116 int box_height;
|
|
117 int i;
|
|
118
|
|
119 /* shift all data when a new datarow arrives */
|
|
120 for (t2 = (HISTORY_SIZE-1); t2 > 0; t2--)
|
|
121 {
|
|
122 for (t1 = 0; t1 < NUM_BANDS; t1++)
|
|
123 {
|
|
124 data2[t1][t2] = data2[t1][t2-1];
|
|
125 }
|
|
126 phase[t2] = phase[t2-1];
|
|
127 }
|
|
128 for (t1 = 0; t1 < NUM_BANDS; t1++)
|
|
129 {
|
|
130 data2[t1][0] = datas.data1[t1];
|
|
131 phase[0] = phase[1] + speed_to_phase(conf_private.wave_speed);
|
|
132 }
|
|
133
|
|
134 glBegin (GL_QUADS);
|
|
135
|
|
136 for (t2 = (HISTORY_SIZE-1); t2 >= 0; t2--)
|
|
137 {
|
|
138 for (t1 = 0; t1 < NUM_BANDS; t1++)
|
|
139 {
|
|
140 basis[t1] = BOTTOM + sin( phase[t2] + (speed_to_phase(conf_private.wave_speed) * t1));
|
|
141 box_height = (int)ceilf( data2[t1][t2] * conf_private.num_blocks );
|
|
142
|
|
143 for (i = 0; i < box_height; i++)
|
|
144 {
|
|
145 if (i < (box_height-1))
|
|
146 {
|
|
147 y_color = (GLfloat)i * (1.0 / (GLfloat)conf_private.num_blocks);
|
|
148 }
|
|
149 else
|
|
150 {
|
|
151 y_color = data2[t1][t2];
|
|
152 }
|
|
153 get_color (&red, &green, &blue, &y_color); // box color
|
|
154 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
155
|
|
156 ulf.xc = FAR_LEFT + (HALF_BOX * 3 * t1) - HALF_BOX;
|
|
157 ulf.yc = basis[t1] + (HALF_BOX_Y * 3 * i) + HALF_BOX_Y;
|
|
158 ulf.zc = (FAR_BACK + t2 * HALF_BOX * 3) - HALF_BOX;
|
|
159
|
|
160 urf.xc = FAR_LEFT + (HALF_BOX * 3 * t1) + HALF_BOX;
|
|
161 urf.yc = basis[t1] + (HALF_BOX_Y * 3 * i) + HALF_BOX_Y;
|
|
162 urf.zc = (FAR_BACK + t2 * HALF_BOX * 3) - HALF_BOX;
|
|
163
|
|
164 lrf.xc = FAR_LEFT + (HALF_BOX * 3 * t1) + HALF_BOX;
|
|
165 lrf.yc = basis[t1] + (HALF_BOX_Y * 3 * i) - HALF_BOX_Y;
|
|
166 lrf.zc = (FAR_BACK + t2 * HALF_BOX * 3) - HALF_BOX;
|
|
167
|
|
168 llf.xc = FAR_LEFT + (HALF_BOX * 3 * t1) - HALF_BOX;
|
|
169 llf.yc = basis[t1] + (HALF_BOX_Y * 3 * i) - HALF_BOX_Y;
|
|
170 llf.zc = (FAR_BACK + t2 * HALF_BOX * 3) - HALF_BOX;
|
|
171
|
|
172 ulb.xc = FAR_LEFT + (HALF_BOX * 3 * t1) - HALF_BOX;
|
|
173 ulb.yc = basis[t1] + (HALF_BOX_Y * 3 * i) + HALF_BOX_Y;
|
|
174 ulb.zc = (FAR_BACK + t2 * HALF_BOX * 3) + HALF_BOX;
|
|
175
|
|
176 urb.xc = FAR_LEFT + (HALF_BOX * 3 * t1) + HALF_BOX;
|
|
177 urb.yc = basis[t1] + (HALF_BOX_Y * 3 * i) + HALF_BOX_Y;
|
|
178 urb.zc = (FAR_BACK + t2 * HALF_BOX * 3) + HALF_BOX;
|
|
179
|
|
180 lrb.xc = FAR_LEFT + (HALF_BOX * 3 * t1) + HALF_BOX;
|
|
181 lrb.yc = basis[t1] + (HALF_BOX_Y * 3 * i) - HALF_BOX_Y;
|
|
182 lrb.zc = (FAR_BACK + t2 * HALF_BOX * 3) + HALF_BOX;
|
|
183
|
|
184 llb.xc = FAR_LEFT + (HALF_BOX * 3 * t1) - HALF_BOX;
|
|
185 llb.yc = basis[t1] + (HALF_BOX_Y * 3 * i) - HALF_BOX_Y;
|
|
186 llb.zc = (FAR_BACK + t2 * HALF_BOX * 3) + HALF_BOX;
|
|
187
|
|
188 // now start drawin'
|
|
189 // start with the front, then left, back, right, finally the top
|
|
190
|
|
191 // "front"
|
|
192 glVertex3f (ulf.xc, ulf.yc, ulf.zc); // "top-left"
|
|
193
|
|
194 glVertex3f (urf.xc, urf.yc, urf.zc); // "top-right"
|
|
195
|
|
196 glVertex3f (lrf.xc, lrf.yc, lrf.zc); // "bottom-right"
|
|
197
|
|
198 glVertex3f (llf.xc, llf.yc, llf.zc); // "bottom-left"
|
|
199
|
|
200 // "back"
|
|
201 glVertex3f (ulb.xc, ulb.yc, ulb.zc); // "top-left"
|
|
202
|
|
203 glVertex3f (urb.xc, urb.yc, urb.zc); // "top-right"
|
|
204
|
|
205 glVertex3f (lrb.xc, lrb.yc, lrb.zc); // "bottom-right"
|
|
206
|
|
207 glVertex3f (llb.xc, llb.yc, llb.zc); // "bottom-left"
|
|
208
|
|
209 // "left"
|
|
210 glVertex3f( llb.xc, llb.yc, llb.zc); // "bottom-in"
|
|
211
|
|
212 glVertex3f( llf.xc, llf.yc, llf.zc); // "bottom-out"
|
|
213
|
|
214 glVertex3f( ulf.xc, ulf.yc, ulf.zc); // "top-out"
|
|
215
|
|
216 glVertex3f( ulb.xc, ulb.yc, ulb.zc); // "top-in"
|
|
217
|
|
218 // "top"
|
|
219 glVertex3f( ulb.xc, ulb.yc, ulb.zc); // "left-in"
|
|
220
|
|
221 glVertex3f( ulf.xc, ulf.yc, ulf.zc); // "left-out"
|
|
222
|
|
223 glVertex3f( urf.xc, urf.yc, urf.zc); // "right-out"
|
|
224
|
|
225 glVertex3f( urb.xc, urb.yc, urb.zc); // "right-in"
|
|
226
|
|
227 // "right"
|
|
228 glVertex3f( urb.xc, urb.yc, urb.zc); // "top-in"
|
|
229
|
|
230 glVertex3f( urf.xc, urf.yc, urf.zc); // "top-out"
|
|
231
|
|
232 glVertex3f( lrf.xc, lrf.yc, lrf.zc); // "bottom-out"
|
|
233
|
|
234 glVertex3f( lrb.xc, lrb.yc, lrb.zc); // "bottom-in"
|
|
235
|
|
236 // "bottom"
|
|
237 glVertex3f( lrb.xc, lrb.yc, lrb.zc); // "right-in"
|
|
238
|
|
239 glVertex3f( lrf.xc, lrf.yc, lrf.zc); // "right-out"
|
|
240
|
|
241 glVertex3f( llf.xc, llf.yc, llf.zc); // "left-out"
|
|
242
|
|
243 glVertex3f( llb.xc, llb.yc, llb.zc); // "left-in"
|
|
244 }
|
|
245 }
|
|
246 }
|
|
247
|
|
248 glEnd ();
|
|
249
|
|
250 }
|
|
251
|
|
252
|
|
253 static void
|
|
254 config_read (ConfigDb * db, char *section_name)
|
|
255 {
|
|
256 bmp_cfg_db_get_float (db, section_name, float_numblocks, &conf_private.num_blocks);
|
|
257 bmp_cfg_db_get_int (db, section_name, float_wavespeed, &conf_private.wave_speed);
|
|
258 }
|
|
259
|
|
260
|
|
261 static void
|
|
262 config_write (ConfigDb * db, char *section_name)
|
|
263 {
|
|
264 bmp_cfg_db_set_float (db, section_name, float_numblocks, conf_private.num_blocks);
|
|
265 bmp_cfg_db_set_int (db, section_name, float_wavespeed, conf_private.wave_speed);
|
|
266 }
|
|
267
|
|
268
|
|
269 static void
|
|
270 config_default ()
|
|
271 {
|
|
272 conf_private.num_blocks = 8.0;
|
|
273 conf_private.wave_speed = 4;
|
|
274 }
|
|
275
|
|
276
|
|
277 static void
|
|
278 blocks_changed (GtkAdjustment * adj)
|
|
279 {
|
|
280 conf_private_new.num_blocks = (int) adj->value;
|
|
281 }
|
|
282
|
|
283
|
|
284 // speeds: pi/8, pi/12, pi/16, pi/20, pi/24, pi/28, pi/32,0
|
|
285 static gfloat speed_to_phase(int speed)
|
|
286 {
|
|
287 gfloat phase;
|
|
288
|
|
289 if (speed == 0)
|
|
290 {
|
|
291 phase = 0;
|
|
292 }
|
|
293 else
|
|
294 {
|
|
295 phase = M_PI_4/(9-speed);
|
|
296 }
|
|
297
|
|
298 return phase;
|
|
299 }
|
|
300
|
|
301 static void
|
|
302 speed_changed (GtkWidget *menuitem, gpointer data)
|
|
303 {
|
|
304 conf_private_new.wave_speed = GPOINTER_TO_INT(data);
|
|
305 }
|
|
306
|
|
307
|
|
308
|
|
309 static void
|
|
310 config_create (GtkWidget * vbox)
|
|
311 {
|
|
312 GtkWidget *hbox;
|
|
313 GtkWidget *label;
|
|
314 GtkObject *adjustment;
|
|
315 GtkWidget *hscale;
|
|
316 GtkWidget *menu;
|
|
317 GtkWidget *menuitem;
|
|
318 GtkWidget *optionmenu;
|
|
319 gchar *speeds[8] = {"0","1","2","3","4","5","6","7"};
|
|
320 int i;
|
|
321
|
|
322 memcpy (&conf_private_new, &conf_private, sizeof (conf_private));
|
|
323
|
|
324 /* number blocks */
|
|
325 hbox = gtk_hbox_new (FALSE, 2);
|
|
326 gtk_widget_show (hbox);
|
|
327 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
|
|
328
|
|
329 label = gtk_label_new ("Max number blocks per stack");
|
|
330 gtk_widget_show (label);
|
|
331 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
|
|
332
|
|
333 adjustment =
|
|
334 gtk_adjustment_new (conf_private_new.num_blocks, 4, 8, 1, 2, 0);
|
|
335 hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
|
|
336 gtk_scale_set_digits (GTK_SCALE (hscale), 0);
|
|
337 gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
|
|
338 gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
|
|
339 gtk_widget_show (hscale);
|
|
340 gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
|
|
341 GTK_SIGNAL_FUNC (blocks_changed), NULL);
|
|
342
|
|
343 /* set wave speed */
|
|
344 hbox = gtk_hbox_new (FALSE, 2);
|
|
345 gtk_widget_show (hbox);
|
|
346 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
|
|
347
|
|
348 label = gtk_label_new ("Wave speed");
|
|
349 gtk_widget_show (label);
|
|
350 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
|
|
351
|
|
352 menu = gtk_menu_new ();
|
|
353 for (i=0; i<8; i++)
|
|
354 {
|
|
355 menuitem = gtk_menu_item_new_with_label(speeds[i]);
|
|
356 gtk_menu_append(GTK_MENU(menu), menuitem);
|
|
357 gtk_widget_show (menuitem);
|
|
358 gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
|
359 GTK_SIGNAL_FUNC (speed_changed), GINT_TO_POINTER(i));
|
|
360 }
|
|
361 optionmenu = gtk_option_menu_new();
|
|
362 gtk_menu_set_active(GTK_MENU(menu), conf_private.wave_speed);
|
|
363 gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu), menu);
|
|
364 gtk_box_pack_start (GTK_BOX (hbox), optionmenu, FALSE, FALSE, 4);
|
|
365 gtk_widget_show (optionmenu);
|
|
366
|
|
367 }
|