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 on
|
|
21 */
|
|
22
|
|
23 /* $Id: theme_pinwheel.c,v 1.5 2002/05/16 20:38:17 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 NUM_PER_RING 8
|
|
35 #define GAP (M_PI_4)
|
|
36
|
|
37 #define RANDOM_HEIGHT_COUNTDOWN 60
|
|
38
|
|
39
|
|
40 static struct
|
|
41 {
|
|
42 gboolean height_random;
|
|
43 gfloat height_set;
|
|
44 gfloat height;
|
|
45 gfloat num_sections;
|
|
46 }
|
|
47 conf_private, conf_private_new;
|
|
48
|
|
49 static config_theme conf = {
|
|
50 NULL,
|
|
51 &conf_private
|
|
52 };
|
|
53
|
|
54 static config_theme conf_new = {
|
|
55 NULL,
|
|
56 &conf_private_new
|
|
57 };
|
|
58
|
|
59
|
|
60 static GLfloat get_x_angle (void);
|
|
61 static void draw_one_frame (gboolean);
|
|
62 static void config_read (ConfigDb *, char *);
|
|
63 static void config_write (ConfigDb *, char *);
|
|
64 static void config_default (void);
|
|
65 static void config_create (GtkWidget *);
|
|
66
|
|
67
|
|
68 static char pinwheel_numsec[] = "pinwheel_numsec";
|
|
69 static char pinwheel_hrandom[] = "pinwheel_hrandom";
|
|
70 static char pinwheel_hset[] = "pinwheel_hset";
|
|
71
|
|
72
|
|
73 iris_theme theme_pinwheel = {
|
|
74 "PinWheel",
|
|
75 "A spectrum of pinwheels",
|
|
76 "Ron Lockwood-Childs",
|
|
77 "pinwheel",
|
|
78 &conf,
|
|
79 &conf_new,
|
|
80 sizeof (conf_private),
|
|
81 config_read,
|
|
82 config_write,
|
|
83 config_default,
|
|
84 config_create,
|
|
85 NULL,
|
|
86 NULL,
|
|
87 NULL,
|
|
88 get_x_angle,
|
|
89 draw_one_frame,
|
|
90 };
|
|
91
|
|
92
|
|
93 static time_t time_random = 0; // timer for random height mode
|
|
94
|
|
95 static GLfloat data2[NUM_BANDS]; // previous freq band data
|
|
96 static GLfloat angle[NUM_BANDS]; // previous angle data
|
|
97 static GLfloat radii[NUM_BANDS + 2] =
|
|
98 { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f,
|
|
99 4.0f, 4.5f, 5.0f, 5.5f, 6.0f, 6.5f, 7.0f, 7.5f,
|
|
100 8.0f
|
|
101 };
|
|
102
|
|
103
|
|
104 static GLfloat
|
|
105 get_x_angle ()
|
|
106 {
|
|
107 return (10.0 + (int) (80.0 * rand () / (RAND_MAX + 1.0)));
|
|
108 }
|
|
109
|
|
110
|
|
111 static void
|
|
112 set_height (void)
|
|
113 {
|
|
114 time_t cur_time = time (NULL); // current time
|
|
115
|
|
116 if (conf_private.height_random)
|
|
117 {
|
|
118 /* we are in random height mode, see if it time to change height */
|
|
119 if (cur_time - time_random > RANDOM_HEIGHT_COUNTDOWN)
|
|
120 {
|
|
121 /* generate float 1 <= x <= 3 */
|
|
122 conf_private.height = ((gfloat) rand () * 2.0 / RAND_MAX) + 1.0;
|
|
123
|
|
124 /* reset timer for when to generate new random height */
|
|
125 time_random = time (NULL);
|
|
126 }
|
|
127 }
|
|
128 else
|
|
129 {
|
|
130 conf_private.height = conf_private.height_set;
|
|
131 }
|
|
132 }
|
|
133
|
|
134
|
|
135 static void
|
|
136 draw_one_frame (gboolean beat)
|
|
137 {
|
|
138 int t1, t2; // loop vars
|
|
139 GLfloat red, green, blue;
|
|
140 GLfloat z = 0.0;
|
|
141 GLfloat scaler = 2.0f; // scales the whole field - lower is bigger
|
|
142 GLfloat scaleh; // height of the bar - lower is smaller
|
|
143 GLfloat xin_up, zin_up, xin_dn, zin_dn, xot_up, zot_up, xot_dn, zot_dn;
|
|
144 GLfloat rin, rot; // radius of inner and outer edges of p-gram
|
|
145 GLfloat angle_up, angle_dn; // angles of top and bottom of p-gram
|
|
146 GLfloat differ; // holds the angle increment
|
|
147 GLfloat maxdropoff = 0.05; // smooth changes in heights
|
|
148 GLfloat angle_step;
|
|
149
|
|
150 /* update bar height (could be changing randomly over time) */
|
|
151 set_height ();
|
|
152 scaleh = conf_private.height;
|
|
153
|
|
154 /* internal routine to shift all data when a new datarow arrives */
|
|
155 for (t1 = 0; t1 < 16; t1++)
|
|
156 {
|
|
157 differ = data2[t1] - datas.data1[t1];
|
|
158 // Rotate counter c.w. if differ positive, c.w. if negative
|
|
159 angle[t1] += (differ * M_PI_4 / 3.0f); // max angle change = +/- PI/12
|
|
160 if (angle[t1] > (2.0f * M_PI))
|
|
161 { // cap angle at 360
|
|
162 angle[t1] -= (2.0f * M_PI);
|
|
163 }
|
|
164 else if (angle[t1] < 0)
|
|
165 { // keep angle positive
|
|
166 angle[t1] += (2.0f * M_PI);
|
|
167 }
|
|
168
|
|
169 // smooth bar height changes
|
|
170 if (datas.data1[t1] > data2[t1])
|
|
171 {
|
|
172 if ((datas.data1[t1] - data2[t1]) > maxdropoff)
|
|
173 data2[t1] += maxdropoff;
|
|
174 else
|
|
175 data2[t1] += datas.data1[t1];
|
|
176 }
|
|
177 else if (datas.data1[t1] < data2[t1])
|
|
178 {
|
|
179 if ((data2[t1] - datas.data1[t1]) > maxdropoff)
|
|
180 data2[t1] -= maxdropoff;
|
|
181 else
|
|
182 data2[t1] -= datas.data1[t1];
|
|
183 }
|
|
184 }
|
|
185
|
|
186 glBegin (GL_QUADS);
|
|
187
|
|
188 for (t1 = 0; t1 < 16; t1++)
|
|
189 { // iterate thru rings
|
|
190
|
|
191 // calculate inner and outer radius for this ring of p-grams
|
|
192 rin = (radii[t1 + 1] - ((radii[1] - radii[0]) / 2.0f)) / scaler;
|
|
193 rot = (radii[t1 + 1] + ((radii[1] - radii[0]) / 2.0f)) / scaler;
|
|
194 for (t2 = 0; t2 < conf_private.num_sections; t2++)
|
|
195 { // iterate thru bars in a single ring
|
|
196
|
|
197 angle_step =
|
|
198 angle[t1] + (t2 * 2 * M_PI / conf_private.num_sections);
|
|
199 if (angle_step > (M_PI * 2))
|
|
200 angle_step -= (M_PI * 2);
|
|
201 else if (angle_step < 0)
|
|
202 angle_step += (M_PI * 2);
|
|
203 // calculate upper and lower angles for this p-gram
|
|
204 angle_up = angle_step + (M_PI_2 / 9.0f);
|
|
205 angle_dn = angle_step - (M_PI_2 / 9.0f);
|
|
206 // now figure out all the p-gram vertices
|
|
207 xin_dn = cos (angle_dn) * rin;
|
|
208 zin_dn = sin (angle_dn) * rin;
|
|
209 xin_up = cos (angle_up) * rin;
|
|
210 zin_up = sin (angle_up) * rin;
|
|
211 xot_dn = cos (angle_dn) * rot;
|
|
212 zot_dn = sin (angle_dn) * rot;
|
|
213 xot_up = cos (angle_up) * rot;
|
|
214 zot_up = sin (angle_up) * rot;
|
|
215
|
|
216 // now start drawin'
|
|
217 // start with the front, then left, back, right, finally the top
|
|
218
|
|
219 // "front"
|
|
220 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
221 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
222 glVertex3f (xot_dn, data2[t1] * scaleh, zot_dn); // "top-right"
|
|
223
|
|
224 get_color (&red, &green, &blue, &z); // bottom color
|
|
225 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
226 glVertex3f (xot_dn, z, zot_dn); // "bottom-right"
|
|
227 glVertex3f (xin_dn, z, zin_dn); // "bottom-left"
|
|
228
|
|
229 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
230 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
231 glVertex3f (xin_dn, data2[t1] * scaleh, zin_dn); // "top-left"
|
|
232
|
|
233 // "left"
|
|
234 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
235 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
236 glVertex3f (xin_dn, data2[t1] * scaleh, zin_dn); // "top-out"
|
|
237
|
|
238 get_color (&red, &green, &blue, &z); // bottom color
|
|
239 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
240 glVertex3f (xin_dn, z, zin_dn); // "bottom-out"
|
|
241 glVertex3f (xin_up, z, zin_up); // "bottom-in"
|
|
242
|
|
243 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
244 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
245 glVertex3f (xin_up, data2[t1] * scaleh, zin_up); // "top-in"
|
|
246
|
|
247 // "back"
|
|
248 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
249 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
250 glVertex3f (xin_up, data2[t1] * scaleh, zin_up); // "top-left"
|
|
251
|
|
252 get_color (&red, &green, &blue, &z); // bottom color
|
|
253 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
254 glVertex3f (xin_up, z, zin_up); // "bottom-left"
|
|
255 glVertex3f (xot_up, z, zot_up); // "bottom-right"
|
|
256
|
|
257 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
258 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
259 glVertex3f (xot_up, data2[t1] * scaleh, zot_up); // "top-right"
|
|
260
|
|
261 // "right"
|
|
262 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
263 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
264 glVertex3f (xot_up, data2[t1] * scaleh, zot_up); // "top-in"
|
|
265
|
|
266 get_color (&red, &green, &blue, &z); // bottom color
|
|
267 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
268 glVertex3f (xot_up, z, zot_up); // "bottom-in"
|
|
269 glVertex3f (xot_dn, z, zot_dn); // "bottom-out"
|
|
270
|
|
271 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
272 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
273 glVertex3f (xot_dn, data2[t1] * scaleh, zot_dn); // "top-out"
|
|
274
|
|
275 // "top"
|
|
276 get_color (&red, &green, &blue, &data2[t1]); // top color
|
|
277 glColor4f (red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f);
|
|
278 glVertex3f (xot_dn, data2[t1] * scaleh, zot_dn); // "out-right"
|
|
279 glVertex3f (xin_dn, data2[t1] * scaleh, zin_dn); // "out-left"
|
|
280 glVertex3f (xin_up, data2[t1] * scaleh, zin_up); // "in-left"
|
|
281 glVertex3f (xot_up, data2[t1] * scaleh, zot_up); // "in-right"
|
|
282
|
|
283 }
|
|
284 }
|
|
285
|
|
286 glEnd ();
|
|
287
|
|
288 }
|
|
289
|
|
290
|
|
291 static void
|
|
292 config_read (ConfigDb * db, char *section_name)
|
|
293 {
|
|
294 bmp_cfg_db_get_float (db, section_name, pinwheel_numsec, &conf_private.num_sections);
|
|
295 bmp_cfg_db_get_bool (db, section_name, pinwheel_hrandom, &conf_private.height_random);
|
|
296 bmp_cfg_db_get_float (db, section_name, pinwheel_hset, &conf_private.height_set);
|
|
297 }
|
|
298
|
|
299
|
|
300 static void
|
|
301 config_write (ConfigDb * db, char *section_name)
|
|
302 {
|
|
303 bmp_cfg_db_set_float (db, section_name, pinwheel_numsec, conf_private.num_sections);
|
|
304 bmp_cfg_db_set_bool (db, section_name, pinwheel_hrandom, conf_private.height_random);
|
|
305 bmp_cfg_db_set_float (db, section_name, pinwheel_hset, conf_private.height_set);
|
|
306 }
|
|
307
|
|
308
|
|
309 static void
|
|
310 config_default ()
|
|
311 {
|
|
312 conf_private.num_sections = 8.0;
|
|
313 conf_private.height_random = FALSE;
|
|
314 conf_private.height_set = 2.0;
|
|
315 conf_private.height = 2.0;
|
|
316 }
|
|
317
|
|
318
|
|
319 static void
|
|
320 sections_changed (GtkAdjustment * adj)
|
|
321 {
|
|
322 conf_private_new.num_sections = (int) adj->value;
|
|
323 }
|
|
324
|
|
325
|
|
326 static void
|
|
327 height_changed (GtkAdjustment * adj)
|
|
328 {
|
|
329 conf_private_new.height_set = (int) adj->value;
|
|
330 }
|
|
331
|
|
332
|
|
333 static void
|
|
334 height_toggled (GtkWidget * widget, GtkScale * height_scale)
|
|
335 {
|
|
336 conf_private_new.height_random = !conf_private_new.height_random;
|
|
337 gtk_widget_set_sensitive (GTK_WIDGET (height_scale),
|
|
338 !conf_private_new.height_random);
|
|
339 }
|
|
340
|
|
341
|
|
342 static void
|
|
343 config_create (GtkWidget * vbox)
|
|
344 {
|
|
345 GtkWidget *hbox;
|
|
346 GtkWidget *button;
|
|
347 GtkWidget *label;
|
|
348 GtkObject *adjustment;
|
|
349 GtkWidget *hscale;
|
|
350
|
|
351 memcpy (&conf_private_new, &conf_private, sizeof (conf_private));
|
|
352
|
|
353 /* number sections per ring */
|
|
354 hbox = gtk_hbox_new (FALSE, 2);
|
|
355 gtk_widget_show (hbox);
|
|
356 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
|
|
357
|
|
358 label = gtk_label_new ("Number sections per ring");
|
|
359 gtk_widget_show (label);
|
|
360 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
|
|
361
|
|
362 adjustment =
|
|
363 gtk_adjustment_new (conf_private_new.num_sections, 4, 20, 1, 5, 0);
|
|
364 hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
|
|
365 gtk_scale_set_digits (GTK_SCALE (hscale), 0);
|
|
366 gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
|
|
367 gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
|
|
368 gtk_widget_show (hscale);
|
|
369 gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
|
|
370 GTK_SIGNAL_FUNC (sections_changed), NULL);
|
|
371
|
|
372 /* random max height */
|
|
373 hbox = gtk_hbox_new (FALSE, 2);
|
|
374 gtk_widget_show (hbox);
|
|
375 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
|
|
376
|
|
377 button = gtk_check_button_new_with_label ("Random height");
|
|
378 gtk_widget_show (button);
|
|
379 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4);
|
|
380 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
|
381 conf_private_new.height_random);
|
|
382
|
|
383 /* explicitly set max height */
|
|
384 hbox = gtk_hbox_new (FALSE, 2);
|
|
385 gtk_widget_show (hbox);
|
|
386 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
|
|
387
|
|
388 label = gtk_label_new ("Maximum height");
|
|
389 gtk_widget_show (label);
|
|
390 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
|
|
391
|
|
392 adjustment =
|
|
393 gtk_adjustment_new (conf_private_new.height_set, 1, 3, 0.1, 1, 0);
|
|
394 hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
|
|
395 gtk_scale_set_digits (GTK_SCALE (hscale), 1);
|
|
396 gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
|
|
397 gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
|
|
398 gtk_widget_set_sensitive (GTK_WIDGET (hscale),
|
|
399 !conf_private_new.height_random);
|
|
400 gtk_widget_show (hscale);
|
|
401 gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
|
|
402 GTK_SIGNAL_FUNC (height_changed), NULL);
|
|
403
|
|
404 /* slider gets enabled/disabled according to random setting */
|
|
405 gtk_signal_connect (GTK_OBJECT (button), "toggled",
|
|
406 GTK_SIGNAL_FUNC (height_toggled), GTK_SCALE (hscale));
|
|
407 }
|