annotate audacious/svis.c @ 119:ba761ed802ab trunk

[svn] s/xmms/Audacious/g
author nenolod
date Thu, 03 Nov 2005 21:56:07 -0800
parents cb178e5ad177
children 0ee0b9b6db7e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "svis.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <gdk/gdk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include "main.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include "mainwin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #include "plugin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include "widget.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include "vis.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 static gint svis_redraw_delays[] = { 1, 2, 4, 8 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 /* FIXME: Are the svis_scope_colors correct? */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 static guint8 svis_scope_colors[] = { 20, 19, 18, 19, 20 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 static guint8 svis_vu_normal_colors[] = { 17, 17, 17, 12, 12, 12, 2, 2 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 #define DRAW_DS_PIXEL(ptr,value) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 *(ptr) = (value); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 *((ptr) + 1) = (value); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 *((ptr) + 76) = (value); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 *((ptr) + 77) = (value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 #define SVIS_HEIGHT 5
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 #define SVIS_WIDTH 38
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 svis_timeout_func(SVis * svis, guchar * data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 static GTimer *timer = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 gulong micros = 9999999;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 gboolean falloff = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 if (!timer) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 timer = g_timer_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 g_timer_start(timer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 g_timer_elapsed(timer, &micros);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 if (micros > 14000)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 g_timer_reset(timer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 if (cfg.vis_type == INPUT_VIS_ANALYZER) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 if (micros > 14000)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 falloff = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 for (i = 0; i < 2; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 if (falloff || data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 if (data && data[i] > svis->vs_data[i])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 svis->vs_data[i] = data[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 else if (falloff) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 if (svis->vs_data[i] >= 2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 svis->vs_data[i] -= 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 svis->vs_data[i] = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 else if (data) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 for (i = 0; i < 75; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 svis->vs_data[i] = data[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 if (micros > 14000) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 if (!svis->vs_refresh_delay) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 svis_draw((Widget *) svis);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 svis->vs_refresh_delay = svis_redraw_delays[cfg.vis_refresh];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 svis->vs_refresh_delay--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 svis_draw(Widget * w)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 SVis *svis = (SVis *) w;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 gint x, y, h;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 guchar svis_color[24][3];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 guchar rgb_data[SVIS_WIDTH * 2 * SVIS_HEIGHT * 2], *ptr, c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 guint32 colors[24];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 GdkRgbCmap *cmap;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 GDK_THREADS_ENTER();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 skin_get_viscolor(bmp_active_skin, svis_color);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 for (y = 0; y < 24; y++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 colors[y] =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 svis_color[y][0] << 16 | svis_color[y][1] << 8 | svis_color[y][2];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 cmap = gdk_rgb_cmap_new(colors, 24);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 memset(rgb_data, 0, SVIS_WIDTH * SVIS_HEIGHT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 if (cfg.vis_type == VIS_ANALYZER) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 switch (cfg.vu_mode) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 case VU_NORMAL:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 for (y = 0; y < 2; y++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 ptr = rgb_data + ((y * 3) * 38);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 h = (svis->vs_data[y] * 7) / 37;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 for (x = 0; x < h; x++, ptr += 5) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 c = svis_vu_normal_colors[x];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 *(ptr) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 *(ptr + 1) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 *(ptr + 2) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 *(ptr + 38) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 *(ptr + 39) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 *(ptr + 40) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 case VU_SMOOTH:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 for (y = 0; y < 2; y++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 ptr = rgb_data + ((y * 3) * SVIS_WIDTH);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 for (x = 0; x < svis->vs_data[y]; x++, ptr++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 c = 17 - ((x * 15) / 37);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 *(ptr) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 *(ptr + 38) = c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 else if (cfg.vis_type == VIS_SCOPE) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 for (x = 0; x < 38; x++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 h = svis->vs_data[x << 1] / 3;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 ptr = rgb_data + ((4 - h) * 38) + x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 *ptr = svis_scope_colors[h];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 gdk_draw_indexed_image(mainwin->window, mainwin_gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 svis->vs_widget.x, svis->vs_widget.y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 svis->vs_widget.width,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 svis->vs_widget.height,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 38, cmap);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 gdk_rgb_cmap_free(cmap);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 GDK_THREADS_LEAVE();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 svis_clear_data(SVis * svis)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 for (i = 0; i < 75; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 svis->vs_data[i] = (cfg.vis_type == VIS_SCOPE) ? 6 : 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 svis_clear(SVis * svis)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 gdk_window_clear_area(mainwin->window, svis->vs_widget.x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 svis->vs_widget.y, svis->vs_widget.width,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 svis->vs_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 SVis *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 create_svis(GList ** wlist,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 GdkPixmap * parent,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 GdkGC * gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 gint x, gint y)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 SVis *svis;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 svis = g_new0(SVis, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 widget_init(&svis->vs_widget, parent, gc, x, y, SVIS_WIDTH, SVIS_HEIGHT,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 widget_list_add(wlist, WIDGET(svis));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 return svis;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 }