|
1653
|
1 /* BMP - Cross-platform multimedia player
|
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
|
3 *
|
|
|
4 * Based on XMMS:
|
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
|
6 *
|
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
|
10 * (at your option) any later version.
|
|
|
11 *
|
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
15 * GNU General Public License for more details.
|
|
|
16 *
|
|
|
17 * You should have received a copy of the GNU General Public License
|
|
|
18 * along with this program; if not, write to the Free Software
|
|
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
20 */
|
|
|
21
|
|
|
22 #include "widgetcore.h"
|
|
|
23
|
|
|
24 #include <glib.h>
|
|
|
25 #include <gdk/gdk.h>
|
|
|
26 #include <string.h>
|
|
|
27
|
|
|
28 #include "main.h"
|
|
|
29 #include "skin.h"
|
|
|
30 #include "widget.h"
|
|
|
31
|
|
|
32 static const gfloat vis_afalloff_speeds[] = { 0.34, 0.5, 1.0, 1.3, 1.6 };
|
|
|
33 static const gfloat vis_pfalloff_speeds[] = { 1.2, 1.3, 1.4, 1.5, 1.6 };
|
|
|
34 static const gint vis_redraw_delays[] = { 1, 2, 4, 8 };
|
|
|
35 static const guint8 vis_scope_colors[] =
|
|
|
36 { 21, 21, 20, 20, 19, 19, 18, 19, 19, 20, 20, 21, 21 };
|
|
|
37
|
|
|
38 void
|
|
|
39 vis_timeout_func(Vis * vis, guchar * data)
|
|
|
40 {
|
|
|
41 static GTimer *timer = NULL;
|
|
|
42 gulong micros = 9999999;
|
|
|
43 gboolean falloff = FALSE;
|
|
|
44 gint i;
|
|
|
45
|
|
|
46 if (!timer) {
|
|
|
47 timer = g_timer_new();
|
|
|
48 g_timer_start(timer);
|
|
|
49 }
|
|
|
50 else {
|
|
|
51 g_timer_elapsed(timer, µs);
|
|
|
52 if (micros > 14000)
|
|
|
53 g_timer_reset(timer);
|
|
|
54
|
|
|
55 }
|
|
|
56
|
|
|
57 if (cfg.vis_type == VIS_ANALYZER) {
|
|
|
58 if (micros > 14000)
|
|
|
59 falloff = TRUE;
|
|
|
60 if (data || falloff) {
|
|
|
61 for (i = 0; i < 75; i++) {
|
|
|
62 if (data && data[i] > vis->vs_data[i]) {
|
|
|
63 vis->vs_data[i] = data[i];
|
|
|
64 if (vis->vs_data[i] > vis->vs_peak[i]) {
|
|
|
65 vis->vs_peak[i] = vis->vs_data[i];
|
|
|
66 vis->vs_peak_speed[i] = 0.01;
|
|
|
67
|
|
|
68 }
|
|
|
69 else if (vis->vs_peak[i] > 0.0) {
|
|
|
70 vis->vs_peak[i] -= vis->vs_peak_speed[i];
|
|
|
71 vis->vs_peak_speed[i] *=
|
|
|
72 vis_pfalloff_speeds[cfg.peaks_falloff];
|
|
|
73 if (vis->vs_peak[i] < vis->vs_data[i])
|
|
|
74 vis->vs_peak[i] = vis->vs_data[i];
|
|
|
75 if (vis->vs_peak[i] < 0.0)
|
|
|
76 vis->vs_peak[i] = 0.0;
|
|
|
77 }
|
|
|
78 }
|
|
|
79 else if (falloff) {
|
|
|
80 if (vis->vs_data[i] > 0.0) {
|
|
|
81 vis->vs_data[i] -=
|
|
|
82 vis_afalloff_speeds[cfg.analyzer_falloff];
|
|
|
83 if (vis->vs_data[i] < 0.0)
|
|
|
84 vis->vs_data[i] = 0.0;
|
|
|
85 }
|
|
|
86 if (vis->vs_peak[i] > 0.0) {
|
|
|
87 vis->vs_peak[i] -= vis->vs_peak_speed[i];
|
|
|
88 vis->vs_peak_speed[i] *=
|
|
|
89 vis_pfalloff_speeds[cfg.peaks_falloff];
|
|
|
90 if (vis->vs_peak[i] < vis->vs_data[i])
|
|
|
91 vis->vs_peak[i] = vis->vs_data[i];
|
|
|
92 if (vis->vs_peak[i] < 0.0)
|
|
|
93 vis->vs_peak[i] = 0.0;
|
|
|
94 }
|
|
|
95 }
|
|
|
96 }
|
|
|
97 }
|
|
|
98 }
|
|
|
99 else if (data) {
|
|
|
100 for (i = 0; i < 75; i++)
|
|
|
101 vis->vs_data[i] = data[i];
|
|
|
102 }
|
|
|
103
|
|
|
104 if (micros > 14000) {
|
|
|
105 if (!vis->vs_refresh_delay) {
|
|
|
106 vis_draw((Widget *) vis);
|
|
|
107 vis->vs_refresh_delay = vis_redraw_delays[cfg.vis_refresh];
|
|
|
108
|
|
|
109 }
|
|
|
110 vis->vs_refresh_delay--;
|
|
|
111 }
|
|
|
112 }
|
|
|
113
|
|
|
114 void
|
|
|
115 vis_draw(Widget * w)
|
|
|
116 {
|
|
|
117 Vis *vis = (Vis *) w;
|
|
|
118 gint x, y, h = 0, h2;
|
|
|
119 guchar vis_color[24][3];
|
|
|
120 guchar rgb_data[152 * 32], *ptr, c;
|
|
|
121 guint32 colors[24];
|
|
|
122 GdkRgbCmap *cmap;
|
|
|
123
|
|
|
124 if (!vis->vs_widget.visible)
|
|
|
125 return;
|
|
|
126
|
|
|
127 skin_get_viscolor(bmp_active_skin, vis_color);
|
|
|
128 for (y = 0; y < 24; y++) {
|
|
|
129 colors[y] =
|
|
|
130 vis_color[y][0] << 16 | vis_color[y][1] << 8 | vis_color[y][2];
|
|
|
131 }
|
|
|
132 cmap = gdk_rgb_cmap_new(colors, 24);
|
|
|
133
|
|
1938
|
134 if (!vis->vs_doublesize) {
|
|
|
135 memset(rgb_data, 0, 76 * 16);
|
|
|
136 for (y = 1; y < 16; y += 2) {
|
|
|
137 ptr = rgb_data + (y * 76);
|
|
|
138 for (x = 0; x < 76; x += 2, ptr += 2)
|
|
|
139 *ptr = 1;
|
|
|
140 }
|
|
|
141 if (cfg.vis_type == VIS_ANALYZER) {
|
|
|
142 for (x = 0; x < 75; x++) {
|
|
|
143 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0)
|
|
|
144 h = vis->vs_data[x >> 2];
|
|
|
145 else if (cfg.analyzer_type == ANALYZER_LINES)
|
|
|
146 h = vis->vs_data[x];
|
|
|
147 if (h && (cfg.analyzer_type == ANALYZER_LINES ||
|
|
|
148 (x % 4) != 3)) {
|
|
|
149 ptr = rgb_data + ((16 - h) * 76) + x;
|
|
|
150 switch (cfg.analyzer_mode) {
|
|
|
151 case ANALYZER_NORMAL:
|
|
|
152 for (y = 0; y < h; y++, ptr += 76)
|
|
|
153 *ptr = 18 - h + y;
|
|
|
154 break;
|
|
|
155 case ANALYZER_FIRE:
|
|
|
156 for (y = 0; y < h; y++, ptr += 76)
|
|
|
157 *ptr = y + 2;
|
|
|
158 break;
|
|
|
159 case ANALYZER_VLINES:
|
|
|
160 for (y = 0; y < h; y++, ptr += 76)
|
|
|
161 *ptr = 18 - h;
|
|
|
162 break;
|
|
|
163 }
|
|
|
164 }
|
|
|
165 }
|
|
|
166 if (cfg.analyzer_peaks) {
|
|
|
167 for (x = 0; x < 75; x++) {
|
|
|
168 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0)
|
|
|
169 h = vis->vs_peak[x >> 2];
|
|
|
170 else if (cfg.analyzer_type == ANALYZER_LINES)
|
|
|
171 h = vis->vs_peak[x];
|
|
|
172 if (h
|
|
|
173 && (cfg.analyzer_type == ANALYZER_LINES
|
|
|
174 || (x % 4) != 3))
|
|
|
175 rgb_data[(16 - h) * 76 + x] = 23;
|
|
1653
|
176 }
|
|
|
177 }
|
|
|
178 }
|
|
1938
|
179 else if (cfg.vis_type == VIS_SCOPE) {
|
|
1653
|
180 for (x = 0; x < 75; x++) {
|
|
1938
|
181 switch (cfg.scope_mode) {
|
|
|
182 case SCOPE_DOT:
|
|
|
183 h = vis->vs_data[x];
|
|
|
184 ptr = rgb_data + ((15 - h) * 76) + x;
|
|
|
185 *ptr = vis_scope_colors[h];
|
|
|
186 break;
|
|
|
187 case SCOPE_LINE:
|
|
|
188 if (x != 74) {
|
|
|
189 h = 15 - vis->vs_data[x];
|
|
|
190 h2 = 15 - vis->vs_data[x + 1];
|
|
|
191 if (h > h2) {
|
|
|
192 y = h;
|
|
|
193 h = h2;
|
|
|
194 h2 = y;
|
|
|
195 }
|
|
|
196 ptr = rgb_data + (h * 76) + x;
|
|
|
197 for (y = h; y <= h2; y++, ptr += 76)
|
|
|
198 *ptr = vis_scope_colors[y - 3];
|
|
|
199
|
|
|
200 }
|
|
|
201 else {
|
|
|
202 h = 15 - vis->vs_data[x];
|
|
|
203 ptr = rgb_data + (h * 76) + x;
|
|
|
204 *ptr = vis_scope_colors[h];
|
|
|
205 }
|
|
|
206 break;
|
|
|
207 case SCOPE_SOLID:
|
|
1653
|
208 h = 15 - vis->vs_data[x];
|
|
1938
|
209 h2 = 9;
|
|
|
210 c = vis_scope_colors[(gint) vis->vs_data[x]];
|
|
1653
|
211 if (h > h2) {
|
|
|
212 y = h;
|
|
|
213 h = h2;
|
|
|
214 h2 = y;
|
|
|
215 }
|
|
|
216 ptr = rgb_data + (h * 76) + x;
|
|
|
217 for (y = h; y <= h2; y++, ptr += 76)
|
|
1938
|
218 *ptr = c;
|
|
|
219 break;
|
|
|
220 }
|
|
|
221 }
|
|
|
222 }
|
|
|
223
|
|
|
224 /* FIXME: The check "shouldn't" be neccessary? */
|
|
|
225 /* if (GTK_IS_WINDOW(vis->vs_window)) { */
|
|
|
226 GDK_THREADS_ENTER();
|
|
|
227 gdk_draw_indexed_image(vis->vs_window, vis->vs_widget.gc,
|
|
|
228 vis->vs_widget.x, vis->vs_widget.y,
|
|
|
229 vis->vs_widget.width, vis->vs_widget.height,
|
|
|
230 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data,
|
|
|
231 76, cmap);
|
|
|
232 GDK_THREADS_LEAVE();
|
|
|
233 /* } else {
|
|
|
234 vis->vs_window = mainwin->window;
|
|
|
235 GDK_THREADS_ENTER();
|
|
|
236 gdk_draw_indexed_image(vis->vs_window, vis->vs_widget.gc,
|
|
|
237 vis->vs_widget.x, vis->vs_widget.y,
|
|
|
238 vis->vs_widget.width, vis->vs_widget.height,
|
|
|
239 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data,
|
|
|
240 76, cmap);
|
|
|
241 GDK_THREADS_LEAVE();
|
|
|
242 }
|
|
|
243 */
|
|
|
244 }
|
|
|
245 else {
|
|
|
246 memset(rgb_data, 0, 152 * 32);
|
|
|
247 for (y = 1; y < 16; y += 2) {
|
|
|
248 ptr = rgb_data + (y * 304);
|
|
|
249 for (x = 0; x < 76; x += 2, ptr += 4) {
|
|
|
250 *ptr = 1;
|
|
|
251 *(ptr + 1) = 1;
|
|
|
252 *(ptr + 152) = 1;
|
|
|
253 *(ptr + 153) = 1;
|
|
|
254 }
|
|
|
255 }
|
|
|
256 if (cfg.vis_type == VIS_ANALYZER) {
|
|
|
257 for (x = 0; x < 75; x++) {
|
|
|
258 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0)
|
|
|
259 h = vis->vs_data[x >> 2];
|
|
|
260 else if (cfg.analyzer_type == ANALYZER_LINES)
|
|
|
261 h = vis->vs_data[x];
|
|
|
262 if (h
|
|
|
263 && (cfg.analyzer_type == ANALYZER_LINES
|
|
|
264 || (x % 4) != 3)) {
|
|
|
265 ptr = rgb_data + ((16 - h) * 304) + (x << 1);
|
|
|
266 switch (cfg.analyzer_mode) {
|
|
|
267 case ANALYZER_NORMAL:
|
|
|
268 for (y = 0; y < h; y++, ptr += 304) {
|
|
|
269 *ptr = 18 - h + y;
|
|
|
270 *(ptr + 1) = 18 - h + y;
|
|
|
271 *(ptr + 152) = 18 - h + y;
|
|
|
272 *(ptr + 153) = 18 - h + y;
|
|
|
273 }
|
|
|
274 break;
|
|
|
275 case ANALYZER_FIRE:
|
|
|
276 for (y = 0; y < h; y++, ptr += 304) {
|
|
|
277 *ptr = y + 2;
|
|
|
278 *(ptr + 1) = y + 2;
|
|
|
279 *(ptr + 152) = y + 2;
|
|
|
280 *(ptr + 153) = y + 2;
|
|
|
281 }
|
|
|
282 break;
|
|
|
283 case ANALYZER_VLINES:
|
|
|
284 for (y = 0; y < h; y++, ptr += 304) {
|
|
|
285 *ptr = 18 - h;
|
|
|
286 *(ptr + 1) = 18 - h;
|
|
|
287 *(ptr + 152) = 18 - h;
|
|
|
288 *(ptr + 153) = 18 - h;
|
|
|
289 }
|
|
|
290
|
|
|
291 break;
|
|
|
292 }
|
|
1653
|
293
|
|
|
294 }
|
|
1938
|
295 }
|
|
|
296 if (cfg.analyzer_peaks) {
|
|
|
297
|
|
|
298 for (x = 0; x < 75; x++) {
|
|
|
299 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0)
|
|
|
300 h = vis->vs_peak[x >> 2];
|
|
|
301 else if (cfg.analyzer_type == ANALYZER_LINES)
|
|
|
302 h = vis->vs_peak[x];
|
|
|
303
|
|
|
304 if (h
|
|
|
305 && (cfg.analyzer_type == ANALYZER_LINES
|
|
|
306 || (x % 4) != 3)) {
|
|
|
307 ptr = rgb_data + (16 - h) * 304 + (x << 1);
|
|
|
308 *ptr = 23;
|
|
|
309 *(ptr + 1) = 23;
|
|
|
310 *(ptr + 152) = 23;
|
|
|
311 *(ptr + 153) = 23;
|
|
|
312 }
|
|
1653
|
313 }
|
|
|
314 }
|
|
|
315 }
|
|
1938
|
316 else if (cfg.vis_type == VIS_SCOPE) {
|
|
|
317 for (x = 0; x < 75; x++) {
|
|
|
318 switch (cfg.scope_mode) {
|
|
|
319 case SCOPE_DOT:
|
|
|
320 h = vis->vs_data[x];
|
|
|
321 ptr = rgb_data + ((15 - h) * 304) + (x << 1);
|
|
|
322 *ptr = vis_scope_colors[h];
|
|
|
323 *(ptr + 1) = vis_scope_colors[h];
|
|
|
324 *(ptr + 152) = vis_scope_colors[h];
|
|
|
325 *(ptr + 153) = vis_scope_colors[h];
|
|
|
326 break;
|
|
|
327 case SCOPE_LINE:
|
|
|
328 if (x != 74) {
|
|
|
329 h = 15 - vis->vs_data[x];
|
|
|
330 h2 = 15 - vis->vs_data[x + 1];
|
|
|
331 if (h > h2) {
|
|
|
332 y = h;
|
|
|
333 h = h2;
|
|
|
334 h2 = y;
|
|
|
335 }
|
|
|
336 ptr = rgb_data + (h * 304) + (x << 1);
|
|
|
337 for (y = h; y <= h2; y++, ptr += 304) {
|
|
|
338 *ptr = vis_scope_colors[y - 3];
|
|
|
339 *(ptr + 1) = vis_scope_colors[y - 3];
|
|
|
340 *(ptr + 152) = vis_scope_colors[y - 3];
|
|
|
341 *(ptr + 153) = vis_scope_colors[y - 3];
|
|
|
342 }
|
|
|
343 }
|
|
|
344 else {
|
|
|
345 h = 15 - vis->vs_data[x];
|
|
|
346 ptr = rgb_data + (h * 304) + (x << 1);
|
|
|
347 *ptr = vis_scope_colors[h];
|
|
|
348 *(ptr + 1) = vis_scope_colors[h];
|
|
|
349 *(ptr + 152) = vis_scope_colors[h];
|
|
|
350 *(ptr + 153) = vis_scope_colors[h];
|
|
|
351 }
|
|
|
352 break;
|
|
|
353 case SCOPE_SOLID:
|
|
|
354 h = 15 - vis->vs_data[x];
|
|
|
355 h2 = 9;
|
|
|
356 c = vis_scope_colors[(gint) vis->vs_data[x]];
|
|
|
357 if (h > h2) {
|
|
|
358 y = h;
|
|
|
359 h = h2;
|
|
|
360 h2 = y;
|
|
|
361 }
|
|
|
362 ptr = rgb_data + (h * 304) + (x << 1);
|
|
|
363 for (y = h; y <= h2; y++, ptr += 304) {
|
|
|
364 *ptr = c;
|
|
|
365 *(ptr + 1) = c;
|
|
|
366 *(ptr + 152) = c;
|
|
|
367 *(ptr + 153) = c;
|
|
|
368 }
|
|
|
369 break;
|
|
|
370 }
|
|
|
371 }
|
|
|
372 }
|
|
1653
|
373
|
|
|
374 GDK_THREADS_ENTER();
|
|
|
375 gdk_draw_indexed_image(vis->vs_window, vis->vs_widget.gc,
|
|
1938
|
376 vis->vs_widget.x << 1,
|
|
|
377 vis->vs_widget.y << 1,
|
|
|
378 vis->vs_widget.width << 1,
|
|
|
379 vis->vs_widget.height << 1,
|
|
|
380 GDK_RGB_DITHER_NONE, (guchar *) rgb_data,
|
|
|
381 152, cmap);
|
|
1653
|
382 GDK_THREADS_LEAVE();
|
|
1938
|
383 }
|
|
1653
|
384
|
|
|
385 gdk_rgb_cmap_free(cmap);
|
|
|
386 }
|
|
|
387
|
|
|
388 void
|
|
|
389 vis_clear_data(Vis * vis)
|
|
|
390 {
|
|
|
391 gint i;
|
|
|
392
|
|
|
393 if (!vis)
|
|
|
394 return;
|
|
|
395
|
|
|
396 for (i = 0; i < 75; i++) {
|
|
|
397 vis->vs_data[i] = (cfg.vis_type == VIS_SCOPE) ? 6 : 0;
|
|
|
398 vis->vs_peak[i] = 0;
|
|
|
399 }
|
|
|
400 }
|
|
|
401
|
|
|
402 void
|
|
1938
|
403 vis_set_doublesize(Vis * vis, gboolean doublesize)
|
|
|
404 {
|
|
|
405 vis->vs_doublesize = doublesize;
|
|
|
406 }
|
|
|
407
|
|
|
408 void
|
|
1653
|
409 vis_clear(Vis * vis)
|
|
|
410 {
|
|
1938
|
411 if (!vis->vs_doublesize)
|
|
|
412 gdk_window_clear_area(vis->vs_window, vis->vs_widget.x,
|
|
|
413 vis->vs_widget.y, vis->vs_widget.width,
|
|
|
414 vis->vs_widget.height);
|
|
|
415 else
|
|
|
416 gdk_window_clear_area(vis->vs_window, vis->vs_widget.x << 1,
|
|
|
417 vis->vs_widget.y << 1,
|
|
|
418 vis->vs_widget.width << 1,
|
|
|
419 vis->vs_widget.height << 1);
|
|
1653
|
420 }
|
|
|
421
|
|
|
422 void
|
|
|
423 vis_set_window(Vis * vis, GdkWindow * window)
|
|
|
424 {
|
|
|
425 vis->vs_window = window;
|
|
|
426 }
|
|
|
427
|
|
|
428 Vis *
|
|
|
429 create_vis(GList ** wlist,
|
|
|
430 GdkPixmap * parent,
|
|
|
431 GdkWindow * window,
|
|
|
432 GdkGC * gc,
|
|
|
433 gint x, gint y,
|
|
1938
|
434 gint width,
|
|
|
435 gboolean doublesize)
|
|
1653
|
436 {
|
|
|
437 Vis *vis;
|
|
|
438
|
|
|
439 vis = g_new0(Vis, 1);
|
|
|
440
|
|
|
441 widget_init(&vis->vs_widget, parent, gc, x, y, width, 16, 1);
|
|
1938
|
442
|
|
|
443 vis->vs_doublesize = doublesize;
|
|
|
444
|
|
1653
|
445 widget_list_add(wlist, WIDGET(vis));
|
|
|
446
|
|
|
447 return vis;
|
|
|
448 }
|