2313
|
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 "ui_main.h"
|
|
30 #include "plugin.h"
|
|
31 #include "widget.h"
|
2328
|
32 #include "playback.h"
|
2313
|
33 #include "vis.h"
|
|
34
|
2525
|
35 #include "ui_skinned_window.h"
|
|
36
|
2313
|
37 static gint svis_redraw_delays[] = { 1, 2, 4, 8 };
|
|
38
|
|
39 /* FIXME: Are the svis_scope_colors correct? */
|
|
40 static guint8 svis_scope_colors[] = { 20, 19, 18, 19, 20 };
|
|
41 static guint8 svis_vu_normal_colors[] = { 17, 17, 17, 12, 12, 12, 2, 2 };
|
|
42
|
|
43 #define DRAW_DS_PIXEL(ptr,value) \
|
|
44 *(ptr) = (value); \
|
|
45 *((ptr) + 1) = (value); \
|
|
46 *((ptr) + 76) = (value); \
|
|
47 *((ptr) + 77) = (value);
|
|
48
|
|
49 #define SVIS_HEIGHT 5
|
|
50 #define SVIS_WIDTH 38
|
|
51
|
|
52 void
|
|
53 svis_timeout_func(SVis * svis, guchar * data)
|
|
54 {
|
|
55 static GTimer *timer = NULL;
|
|
56 gulong micros = 9999999;
|
|
57 gboolean falloff = FALSE;
|
|
58 gint i;
|
|
59
|
|
60 if (!timer) {
|
|
61 timer = g_timer_new();
|
|
62 g_timer_start(timer);
|
|
63 }
|
|
64 else {
|
|
65 g_timer_elapsed(timer, µs);
|
|
66 if (micros > 14000)
|
|
67 g_timer_reset(timer);
|
|
68
|
|
69 }
|
|
70
|
|
71 if (cfg.vis_type == VIS_VOICEPRINT) {
|
|
72 if (micros > 14000)
|
|
73 falloff = TRUE;
|
|
74
|
|
75 for (i = 0; i < 2; i++) {
|
|
76 if (falloff || data) {
|
|
77 if (data && data[i] > svis->vs_data[i])
|
|
78 svis->vs_data[i] = data[i];
|
|
79 else if (falloff) {
|
|
80 if (svis->vs_data[i] >= 2)
|
|
81 svis->vs_data[i] -= 2;
|
|
82 else
|
|
83 svis->vs_data[i] = 0;
|
|
84 }
|
|
85 }
|
|
86
|
|
87 }
|
|
88 }
|
|
89 else if (data) {
|
|
90 for (i = 0; i < 75; i++)
|
|
91 svis->vs_data[i] = data[i];
|
|
92 }
|
|
93
|
|
94 if (micros > 14000) {
|
|
95 if (!svis->vs_refresh_delay) {
|
|
96 svis_draw((Widget *) svis);
|
|
97 svis->vs_refresh_delay = svis_redraw_delays[cfg.vis_refresh];
|
|
98
|
|
99 }
|
|
100 svis->vs_refresh_delay--;
|
|
101 }
|
|
102 }
|
|
103
|
|
104 void
|
|
105 svis_draw(Widget * w)
|
|
106 {
|
|
107 SVis *svis = (SVis *) w;
|
|
108 gint x, y, h;
|
|
109 guchar svis_color[24][3];
|
|
110 guchar rgb_data[SVIS_WIDTH * 2 * SVIS_HEIGHT * 2], *ptr, c;
|
|
111 guint32 colors[24];
|
|
112 GdkRgbCmap *cmap;
|
|
113
|
|
114 GDK_THREADS_ENTER();
|
|
115
|
|
116 skin_get_viscolor(bmp_active_skin, svis_color);
|
|
117 for (y = 0; y < 24; y++) {
|
|
118 colors[y] =
|
|
119 svis_color[y][0] << 16 | svis_color[y][1] << 8 | svis_color[y][2];
|
|
120 }
|
|
121 cmap = gdk_rgb_cmap_new(colors, 24);
|
|
122
|
|
123 if (!cfg.doublesize) {
|
|
124 memset(rgb_data, 0, SVIS_WIDTH * SVIS_HEIGHT);
|
|
125 if (cfg.vis_type == VIS_ANALYZER && !playback_get_paused() && playback_get_playing()){
|
|
126 for(y=0; y < SVIS_HEIGHT; y++){
|
|
127 if (cfg.analyzer_type == ANALYZER_BARS){
|
|
128 for(x=0;x< SVIS_WIDTH; x++){
|
|
129 if(svis->vs_data[x] > y << 1)
|
|
130 {
|
|
131 rgb_data[x*3+ (SVIS_HEIGHT - y) * SVIS_WIDTH] = 23;
|
|
132 rgb_data[x*3+1 + (SVIS_HEIGHT - y) * SVIS_WIDTH] = 23;
|
|
133
|
|
134 }
|
|
135 }
|
|
136 }
|
|
137 else{
|
|
138 for(x=0;x< SVIS_WIDTH; x++){
|
|
139 if(svis->vs_data[x] > y << 1)
|
|
140 {
|
|
141 rgb_data[x + (SVIS_HEIGHT - y) * SVIS_WIDTH] = 23;
|
|
142 }
|
|
143 }
|
|
144 }
|
|
145 }
|
|
146 }
|
|
147 else if (cfg.vis_type == VIS_VOICEPRINT){
|
|
148 switch (cfg.vu_mode) {
|
|
149 case VU_NORMAL:
|
|
150 for (y = 0; y < 2; y++) {
|
|
151 ptr = rgb_data + ((y * 3) * 38);
|
|
152 h = (svis->vs_data[y] * 7) / 37;
|
|
153 for (x = 0; x < h; x++, ptr += 5) {
|
|
154 c = svis_vu_normal_colors[x];
|
|
155 *(ptr) = c;
|
|
156 *(ptr + 1) = c;
|
|
157 *(ptr + 2) = c;
|
|
158 *(ptr + 38) = c;
|
|
159 *(ptr + 39) = c;
|
|
160 *(ptr + 40) = c;
|
|
161 }
|
|
162 }
|
|
163 break;
|
|
164 case VU_SMOOTH:
|
|
165 for (y = 0; y < 2; y++) {
|
|
166 ptr = rgb_data + ((y * 3) * SVIS_WIDTH);
|
|
167 for (x = 0; x < svis->vs_data[y]; x++, ptr++) {
|
|
168 c = 17 - ((x * 15) / 37);
|
|
169 *(ptr) = c;
|
|
170 *(ptr + 38) = c;
|
|
171 }
|
|
172 }
|
|
173 break;
|
|
174 }
|
|
175 }
|
|
176 else if (cfg.vis_type == VIS_SCOPE) {
|
|
177 for (x = 0; x < 38; x++) {
|
|
178 h = svis->vs_data[x << 1] / 3;
|
|
179 ptr = rgb_data + ((4 - h) * 38) + x;
|
|
180 *ptr = svis_scope_colors[h];
|
|
181 }
|
|
182 }
|
|
183
|
2525
|
184 gdk_draw_indexed_image(mainwin->window, SKINNED_WINDOW(mainwin)->gc,
|
2313
|
185 svis->vs_widget.x, svis->vs_widget.y,
|
|
186 svis->vs_widget.width,
|
|
187 svis->vs_widget.height,
|
|
188 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data,
|
|
189 38, cmap);
|
|
190 }
|
|
191 else { /* doublesize */
|
|
192
|
|
193 memset(rgb_data, 0, SVIS_WIDTH * 2 * SVIS_HEIGHT * 2);
|
|
194 if (cfg.vis_type == VIS_ANALYZER && !playback_get_paused() && playback_get_playing()){
|
|
195 for(y=0; y < SVIS_HEIGHT; y++){
|
|
196 if (cfg.analyzer_type == ANALYZER_BARS){
|
|
197 for(x=0;x< SVIS_WIDTH; x++){
|
|
198 if(svis->vs_data[x] > y << 1)
|
|
199 {
|
|
200 ptr = rgb_data + x * 6 + (SVIS_HEIGHT * 2 - y * 2) * SVIS_WIDTH * 2;
|
|
201 DRAW_DS_PIXEL(ptr, 23);
|
|
202 DRAW_DS_PIXEL(ptr + 2, 23);
|
|
203 }
|
|
204 }
|
|
205 }
|
|
206 else{
|
|
207 for(x=0;x< SVIS_WIDTH; x++){
|
|
208 if(svis->vs_data[x] > y << 1)
|
|
209 {
|
|
210 ptr = rgb_data + x * 2 + (SVIS_HEIGHT * 2 - y * 2) * SVIS_WIDTH * 2;
|
|
211 DRAW_DS_PIXEL(ptr, 23);
|
|
212 }
|
|
213 }
|
|
214 }
|
|
215 }
|
|
216 }
|
|
217 else if (cfg.vis_type == VIS_VOICEPRINT){
|
|
218 switch (cfg.vu_mode) {
|
|
219 case VU_NORMAL:
|
|
220 for (y = 0; y < 2; y++) {
|
|
221 ptr = rgb_data + ((y * 3) * 152);
|
|
222 h = (svis->vs_data[y] * 8) / 37;
|
|
223 for (x = 0; x < h; x++, ptr += 10) {
|
|
224 c = svis_vu_normal_colors[x];
|
|
225 DRAW_DS_PIXEL(ptr, c);
|
|
226 DRAW_DS_PIXEL(ptr + 2, c);
|
|
227 DRAW_DS_PIXEL(ptr + 4, c);
|
|
228 DRAW_DS_PIXEL(ptr + 152, c);
|
|
229 DRAW_DS_PIXEL(ptr + 154, c);
|
|
230 DRAW_DS_PIXEL(ptr + 156, c);
|
|
231 }
|
|
232 }
|
|
233 break;
|
|
234 case VU_SMOOTH:
|
|
235 for (y = 0; y < 2; y++) {
|
|
236 ptr = rgb_data + ((y * 3) * 152);
|
|
237 for (x = 0; x < svis->vs_data[y]; x++, ptr += 2) {
|
|
238 c = 17 - ((x * 15) / 37);
|
|
239 DRAW_DS_PIXEL(ptr, c);
|
|
240 DRAW_DS_PIXEL(ptr + 152, c);
|
|
241 }
|
|
242 }
|
|
243 break;
|
|
244 }
|
|
245 }
|
|
246 else if (cfg.vis_type == VIS_SCOPE) {
|
|
247 for (x = 0; x < 38; x++) {
|
|
248 h = svis->vs_data[x << 1] / 3;
|
|
249 ptr = rgb_data + ((4 - h) * 152) + (x << 1);
|
|
250 *ptr = svis_scope_colors[h];
|
|
251 *(ptr + 1) = svis_scope_colors[h];
|
|
252 *(ptr + 76) = svis_scope_colors[h];
|
|
253 *(ptr + 77) = svis_scope_colors[h];
|
|
254 }
|
|
255 }
|
|
256
|
2525
|
257 gdk_draw_indexed_image(mainwin->window, SKINNED_WINDOW(mainwin)->gc,
|
2313
|
258 svis->vs_widget.x << 1,
|
|
259 svis->vs_widget.y << 1,
|
|
260 svis->vs_widget.width << 1,
|
|
261 svis->vs_widget.height << 1,
|
|
262 GDK_RGB_DITHER_NONE, (guchar *) rgb_data,
|
|
263 76, cmap);
|
|
264 }
|
|
265 gdk_rgb_cmap_free(cmap);
|
|
266 GDK_THREADS_LEAVE();
|
|
267 }
|
|
268
|
|
269 void
|
|
270 svis_clear_data(SVis * svis)
|
|
271 {
|
|
272 gint i;
|
|
273
|
|
274 if (!svis)
|
|
275 return;
|
|
276
|
|
277 for (i = 0; i < 75; i++) {
|
|
278 svis->vs_data[i] = (cfg.vis_type == VIS_SCOPE) ? 6 : 0;
|
|
279 }
|
|
280 }
|
|
281
|
|
282 void
|
|
283 svis_clear(SVis * svis)
|
|
284 {
|
|
285 if (!cfg.doublesize)
|
|
286 gdk_window_clear_area(mainwin->window, svis->vs_widget.x,
|
|
287 svis->vs_widget.y, svis->vs_widget.width,
|
|
288 svis->vs_widget.height);
|
|
289 else
|
|
290 gdk_window_clear_area(mainwin->window, svis->vs_widget.x << 1,
|
|
291 svis->vs_widget.y << 1,
|
|
292 svis->vs_widget.width << 1,
|
|
293 svis->vs_widget.height << 1);
|
|
294 }
|
|
295
|
|
296 SVis *
|
|
297 create_svis(GList ** wlist,
|
|
298 GdkPixmap * parent,
|
|
299 GdkGC * gc,
|
|
300 gint x, gint y)
|
|
301 {
|
|
302 SVis *svis;
|
|
303
|
|
304 svis = g_new0(SVis, 1);
|
|
305 widget_init(&svis->vs_widget, parent, gc, x, y, SVIS_WIDTH, SVIS_HEIGHT,
|
|
306 1);
|
|
307
|
|
308 widget_list_add(wlist, WIDGET(svis));
|
|
309 return svis;
|
|
310 }
|