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