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 #include <stdlib.h>
|
|
20 #include <math.h>
|
|
21 #include <GL/gl.h>
|
|
22 #include <audacious/configdb.h>
|
|
23 #include "iris.h"
|
|
24
|
|
25
|
|
26 static char spectrum_proportional[] = "spectrum_proportional";
|
|
27
|
|
28 static GLfloat peak[16]; // where the peak values are stored
|
|
29
|
|
30 static struct
|
|
31 {
|
|
32 gboolean proportional;
|
|
33 }
|
|
34 conf_private, conf_private_new;
|
|
35
|
|
36 static config_theme conf = {
|
|
37 NULL,
|
|
38 &conf_private
|
|
39 };
|
|
40
|
|
41 static config_theme conf_new = {
|
|
42 NULL,
|
|
43 &conf_private_new
|
|
44 };
|
|
45
|
|
46
|
|
47 static void config_read (ConfigDb *, char *);
|
|
48 static void config_write (ConfigDb *, char *);
|
|
49 static void config_default (void);
|
|
50 static void config_create (GtkWidget *);
|
|
51 static void init_draw_mode (void);
|
|
52 static GLfloat get_x_angle (void);
|
|
53 static void draw_one_frame (gboolean);
|
|
54
|
|
55
|
|
56 iris_theme theme_spectrum = {
|
|
57 "Spectrum",
|
|
58 "A simple spectrum",
|
|
59 "Cédric Delfosse (cdelfosse@free.fr)",
|
|
60 "spectrum",
|
|
61 &conf,
|
|
62 &conf_new,
|
|
63 sizeof (conf_private),
|
|
64 config_read,
|
|
65 config_write,
|
|
66 config_default,
|
|
67 config_create,
|
|
68 NULL,
|
|
69 NULL,
|
|
70 init_draw_mode,
|
|
71 get_x_angle,
|
|
72 draw_one_frame,
|
|
73 };
|
|
74
|
|
75
|
|
76 static void
|
|
77 init_draw_mode ()
|
|
78 {
|
|
79 memset (peak, 0x00, 16);
|
|
80 }
|
|
81
|
|
82
|
|
83 static GLfloat
|
|
84 get_x_angle ()
|
|
85 {
|
|
86 return (10.0 + (int) (80.0 * rand () / (RAND_MAX + 1.0)));
|
|
87 }
|
|
88
|
|
89
|
|
90 static void
|
|
91 draw_one_frame (gboolean beat)
|
|
92 {
|
|
93 GLfloat x1, x2;
|
|
94 GLfloat bar_length = 0.30;
|
|
95 GLfloat bar_distance = 0.1;
|
|
96 GLfloat bar_deep = 1.5;
|
|
97 GLfloat y, y2;
|
|
98 GLfloat red, green, blue;
|
|
99 GLfloat z = 0.0;
|
|
100 static GLfloat data[16]; // where the spectrum values are stored
|
|
101 int l;
|
|
102
|
|
103 for (l = 0; l < 16; l++)
|
|
104 {
|
|
105 if (datas.data1[l] > data[l])
|
|
106 data[l] = datas.data1[l];
|
|
107 else
|
|
108 data[l] -= 0.015;
|
|
109 if (data[l] < 0.0)
|
|
110 data[l] = 0.0;
|
|
111 }
|
|
112
|
|
113 glBegin (GL_TRIANGLES);
|
|
114
|
|
115 x1 = -(bar_length * 16.0 + bar_distance * 15.0) / 2.0;
|
|
116 x2 = x1 + bar_length;
|
|
117
|
|
118 for (l = 0; l < 16; l++)
|
|
119 {
|
|
120 GLfloat width;
|
|
121 y = data[l] * 4;
|
|
122
|
|
123 if (peak[l] < data[l])
|
|
124 {
|
|
125 peak[l] = data[l];
|
|
126 if (beat)
|
|
127 peak[l] += 0.2;
|
|
128 }
|
|
129 else
|
|
130 peak[l] -= 0.007;
|
|
131 if (conf_private.proportional)
|
|
132 width = peak[l];
|
|
133 else
|
|
134 width = bar_deep / 2;
|
|
135 if (peak[l] < 0.0)
|
|
136 peak[l] = 0.0;
|
|
137 else
|
|
138 {
|
|
139 y2 = peak[l] * 4 + 0.1;
|
|
140 get_color (&red, &green, &blue, &peak[l]);
|
|
141 glColor4f (red * 1.5, green * 1.5, blue * 1.5, 0.8);
|
|
142 glVertex3f (x1, y2, -width);
|
|
143 glVertex3f (x2, y2, -width);
|
|
144 glVertex3f (x2, y2, +width);
|
|
145 glVertex3f (x2, y2, +width);
|
|
146 glVertex3f (x1, y2, -width);
|
|
147 glVertex3f (x1, y2, +width);
|
|
148 }
|
|
149
|
|
150 if (y > 0.0)
|
|
151 {
|
|
152 /* one side */
|
|
153 get_color (&red, &green, &blue, &data[l]);
|
|
154 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
155 glVertex3f (x1, y, -width);
|
|
156 glVertex3f (x2, y, -width);
|
|
157
|
|
158 get_color (&red, &green, &blue, &z);
|
|
159 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
160 glVertex3f (x1, 0, -width);
|
|
161 glVertex3f (x1, 0, -width);
|
|
162 glVertex3f (x2, 0, -width);
|
|
163
|
|
164 get_color (&red, &green, &blue, &data[l]);
|
|
165 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
166 glVertex3f (x2, y, -width);
|
|
167
|
|
168 /* top */
|
|
169 glColor4f (red, green, blue, 0.5);
|
|
170 glVertex3f (x1, y, -width);
|
|
171 glVertex3f (x2, y, -width);
|
|
172 glVertex3f (x2, y, +width);
|
|
173 glVertex3f (x2, y, +width);
|
|
174 glVertex3f (x1, y, -width);
|
|
175 glVertex3f (x1, y, +width);
|
|
176
|
|
177 /* other side */
|
|
178 get_color (&red, &green, &blue, &data[l]);
|
|
179 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
180 glVertex3f (x1, y, width);
|
|
181 glVertex3f (x2, y, width);
|
|
182
|
|
183 get_color (&red, &green, &blue, &z);
|
|
184 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
185 glVertex3f (x1, 0, width);
|
|
186 glVertex3f (x1, 0, width);
|
|
187 glVertex3f (x2, 0, width);
|
|
188
|
|
189 get_color (&red, &green, &blue, &data[l]);
|
|
190 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
191 glVertex3f (x2, y, width);
|
|
192
|
|
193 /**/ glVertex3f (x1, y, +width);
|
|
194 glVertex3f (x1, y, -width);
|
|
195
|
|
196 get_color (&red, &green, &blue, &z);
|
|
197 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
198 glVertex3f (x1, 0, -width);
|
|
199
|
|
200 glVertex3f (x1, 0, -width);
|
|
201 glVertex3f (x1, 0, +width);
|
|
202
|
|
203 get_color (&red, &green, &blue, &data[l]);
|
|
204 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
205 glVertex3f (x1, y, +width);
|
|
206
|
|
207 /**/ glVertex3f (x2, y, +width);
|
|
208 glVertex3f (x2, y, -width);
|
|
209
|
|
210 get_color (&red, &green, &blue, &z);
|
|
211 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
212 glVertex3f (x2, 0, -width);
|
|
213
|
|
214 glVertex3f (x2, 0, -width);
|
|
215 glVertex3f (x2, 0, +width);
|
|
216
|
|
217 get_color (&red, &green, &blue, &data[l]);
|
|
218 glColor4f (red / 2, green / 2, blue / 2, 0.5);
|
|
219 glVertex3f (x2, y, +width);
|
|
220 }
|
|
221
|
|
222 x1 += bar_length + bar_distance;
|
|
223 x2 += bar_length + bar_distance;
|
|
224
|
|
225 }
|
|
226
|
|
227 glEnd ();
|
|
228
|
|
229 }
|
|
230
|
|
231
|
|
232 static void
|
|
233 config_read (ConfigDb * db, char *section_name)
|
|
234 {
|
|
235 bmp_cfg_db_get_bool (db, section_name, spectrum_proportional, &conf_private.proportional);
|
|
236 }
|
|
237
|
|
238 static void
|
|
239 config_write (ConfigDb * db, char *section_name)
|
|
240 {
|
|
241 bmp_cfg_db_set_bool (db, section_name, spectrum_proportional, conf_private.proportional);
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 config_default ()
|
|
246 {
|
|
247 conf_private.proportional = TRUE;
|
|
248 }
|
|
249
|
|
250
|
|
251 static void
|
|
252 proportional_toggled (GtkWidget * widget, gpointer data)
|
|
253 {
|
|
254 conf_private_new.proportional = !conf_private_new.proportional;
|
|
255 }
|
|
256
|
|
257
|
|
258 static void
|
|
259 config_create (GtkWidget * vbox)
|
|
260 {
|
|
261 GtkWidget *hbox;
|
|
262 GtkWidget *button;
|
|
263
|
|
264 memcpy (&conf_private_new, &conf_private, sizeof (conf_private_new));
|
|
265
|
|
266 /* proportional mode */
|
|
267 hbox = gtk_hbox_new (FALSE, 2);
|
|
268 gtk_widget_show (hbox);
|
|
269 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
|
|
270
|
|
271 button = gtk_check_button_new_with_label ("Proportional mode");
|
|
272 gtk_widget_show (button);
|
|
273 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4);
|
|
274 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
|
275 conf_private_new.proportional);
|
|
276 gtk_signal_connect (GTK_OBJECT (button), "toggled",
|
|
277 GTK_SIGNAL_FUNC (proportional_toggled), NULL);
|
|
278 }
|