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