Mercurial > audlegacy
annotate src/audacious/ui_vis.c @ 3119:4ba71e08fed0 trunk
Automated merge with ssh://hg.atheme.org//hg/audacious
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Thu, 19 Jul 2007 22:48:30 -0500 |
parents | 1912eba1004b |
children | 3b6d316f8b09 |
rev | line source |
---|---|
3020 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Audacious development team. | |
4 * | |
5 * Based on: | |
6 * BMP - Cross-platform multimedia player | |
7 * Copyright (C) 2003-2004 BMP development team. | |
8 * XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; under version 2 of the License. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
23 */ | |
24 | |
25 #include "widgets/widgetcore.h" | |
26 #include "ui_vis.h" | |
27 #include "main.h" | |
28 #include "util.h" | |
29 #include "playback.h" | |
30 | |
31 static const gfloat vis_afalloff_speeds[] = { 0.34, 0.5, 1.0, 1.3, 1.6 }; | |
32 static const gfloat vis_pfalloff_speeds[] = { 1.2, 1.3, 1.4, 1.5, 1.6 }; | |
33 static const gint vis_redraw_delays[] = { 1, 2, 4, 8 }; | |
34 static const guint8 vis_scope_colors[] = | |
35 { 21, 21, 20, 20, 19, 19, 18, 19, 19, 20, 20, 21, 21 }; | |
36 static guchar voiceprint_data[76*16]; | |
37 | |
38 enum { | |
39 DOUBLED, | |
40 LAST_SIGNAL | |
41 }; | |
42 | |
43 static void ui_vis_class_init (UiVisClass *klass); | |
44 static void ui_vis_init (UiVis *vis); | |
45 static void ui_vis_destroy (GtkObject *object); | |
46 static void ui_vis_realize (GtkWidget *widget); | |
47 static void ui_vis_unrealize (GtkWidget *widget); | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
48 static void ui_vis_map (GtkWidget *widget); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
49 static void ui_vis_unmap (GtkWidget *widget); |
3020 | 50 static void ui_vis_size_request (GtkWidget *widget, GtkRequisition *requisition); |
51 static void ui_vis_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
52 static gboolean ui_vis_expose (GtkWidget *widget, GdkEventExpose *event); | |
53 static void ui_vis_toggle_doublesize (UiVis *vis); | |
54 | |
55 static GtkWidgetClass *parent_class = NULL; | |
56 static guint vis_signals[LAST_SIGNAL] = { 0 }; | |
57 | |
58 GType ui_vis_get_type() { | |
59 static GType vis_type = 0; | |
60 if (!vis_type) { | |
61 static const GTypeInfo vis_info = { | |
62 sizeof (UiVisClass), | |
63 NULL, | |
64 NULL, | |
65 (GClassInitFunc) ui_vis_class_init, | |
66 NULL, | |
67 NULL, | |
68 sizeof (UiVis), | |
69 0, | |
70 (GInstanceInitFunc) ui_vis_init, | |
71 }; | |
72 vis_type = g_type_register_static (GTK_TYPE_WIDGET, "UiVis", &vis_info, 0); | |
73 } | |
74 | |
75 return vis_type; | |
76 } | |
77 | |
78 static void ui_vis_class_init(UiVisClass *klass) { | |
79 GtkObjectClass *object_class; | |
80 GtkWidgetClass *widget_class; | |
81 | |
82 object_class = (GtkObjectClass*) klass; | |
83 widget_class = (GtkWidgetClass*) klass; | |
84 parent_class = gtk_type_class (gtk_widget_get_type ()); | |
85 | |
86 object_class->destroy = ui_vis_destroy; | |
87 | |
88 widget_class->realize = ui_vis_realize; | |
89 widget_class->unrealize = ui_vis_unrealize; | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
90 widget_class->map = ui_vis_map; |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
91 widget_class->unmap = ui_vis_unmap; |
3020 | 92 widget_class->expose_event = ui_vis_expose; |
93 widget_class->size_request = ui_vis_size_request; | |
94 widget_class->size_allocate = ui_vis_size_allocate; | |
95 | |
96 klass->doubled = ui_vis_toggle_doublesize; | |
97 | |
98 vis_signals[DOUBLED] = | |
99 g_signal_new ("toggle-double-size", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
100 G_STRUCT_OFFSET (UiVisClass, doubled), NULL, NULL, | |
101 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
102 } | |
103 | |
104 static void ui_vis_init(UiVis *vis) { | |
105 memset(voiceprint_data, 0, 16*76); | |
106 } | |
107 | |
108 GtkWidget* ui_vis_new(GtkWidget *fixed, gint x, gint y, gint width) { | |
109 UiVis *vis = g_object_new (ui_vis_get_type (), NULL); | |
110 | |
111 vis->x = x; | |
112 vis->y = y; | |
113 | |
114 vis->width = width; | |
115 vis->height = 16; | |
116 | |
117 vis->fixed = fixed; | |
118 vis->double_size = FALSE; | |
119 | |
120 vis->visible_window = TRUE; | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
121 vis->event_window = NULL; |
3020 | 122 |
123 gtk_fixed_put(GTK_FIXED(vis->fixed), GTK_WIDGET(vis), vis->x, vis->y); | |
124 | |
125 return GTK_WIDGET(vis); | |
126 } | |
127 | |
128 static void ui_vis_destroy(GtkObject *object) { | |
129 UiVis *vis; | |
130 | |
131 g_return_if_fail (object != NULL); | |
132 g_return_if_fail (UI_IS_VIS (object)); | |
133 | |
134 vis = UI_VIS (object); | |
135 | |
136 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
137 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
138 } | |
139 | |
140 static void ui_vis_realize(GtkWidget *widget) { | |
141 UiVis *vis; | |
142 GdkWindowAttr attributes; | |
143 gint attributes_mask; | |
144 | |
145 g_return_if_fail (widget != NULL); | |
146 g_return_if_fail (UI_IS_VIS(widget)); | |
147 | |
148 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
149 vis = UI_VIS(widget); | |
150 | |
151 attributes.x = widget->allocation.x; | |
152 attributes.y = widget->allocation.y; | |
153 attributes.width = widget->allocation.width; | |
154 attributes.height = widget->allocation.height; | |
155 attributes.window_type = GDK_WINDOW_CHILD; | |
156 attributes.event_mask = gtk_widget_get_events(widget); | |
157 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK; | |
158 | |
159 if (vis->visible_window) | |
160 { | |
161 attributes.visual = gtk_widget_get_visual(widget); | |
162 attributes.colormap = gtk_widget_get_colormap(widget); | |
163 attributes.wclass = GDK_INPUT_OUTPUT; | |
164 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
165 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
3052 | 166 GTK_WIDGET_UNSET_FLAGS(widget, GTK_NO_WINDOW); |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
167 gdk_window_set_user_data(widget->window, widget); |
3020 | 168 } |
169 else | |
170 { | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
171 widget->window = gtk_widget_get_parent_window (widget); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
172 g_object_ref (widget->window); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
173 |
3020 | 174 attributes.wclass = GDK_INPUT_ONLY; |
175 attributes_mask = GDK_WA_X | GDK_WA_Y; | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
176 vis->event_window = gdk_window_new (widget->window, &attributes, attributes_mask); |
3052 | 177 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW); |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
178 gdk_window_set_user_data(vis->event_window, widget); |
3020 | 179 } |
180 | |
181 widget->style = gtk_style_attach(widget->style, widget->window); | |
182 } | |
183 | |
184 static void ui_vis_unrealize(GtkWidget *widget) { | |
185 UiVis *vis; | |
186 vis = UI_VIS(widget); | |
187 | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
188 if ( vis->event_window != NULL ) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
189 { |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
190 gdk_window_set_user_data( vis->event_window , NULL ); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
191 gdk_window_destroy( vis->event_window ); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
192 vis->event_window = NULL; |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
193 } |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
194 |
3020 | 195 if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
196 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); | |
197 } | |
198 | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
199 static void ui_vis_map(GtkWidget *widget) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
200 { |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
201 UiVis *vis; |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
202 vis = UI_VIS(widget); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
203 |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
204 if (vis->event_window != NULL) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
205 gdk_window_show (vis->event_window); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
206 |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
207 if (GTK_WIDGET_CLASS (parent_class)->map) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
208 (* GTK_WIDGET_CLASS (parent_class)->map) (widget); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
209 } |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
210 |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
211 static void ui_vis_unmap (GtkWidget *widget) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
212 { |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
213 UiVis *vis; |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
214 vis = UI_VIS(widget); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
215 |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
216 if (vis->event_window != NULL) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
217 gdk_window_hide (vis->event_window); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
218 |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
219 if (GTK_WIDGET_CLASS (parent_class)->unmap) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
220 (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
221 } |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
222 |
3020 | 223 static void ui_vis_size_request(GtkWidget *widget, GtkRequisition *requisition) { |
224 UiVis *vis = UI_VIS(widget); | |
225 | |
226 requisition->width = vis->width*(1+vis->double_size); | |
227 requisition->height = vis->height*(1+vis->double_size); | |
228 } | |
229 | |
230 static void ui_vis_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
231 UiVis *vis = UI_VIS (widget); | |
232 | |
233 widget->allocation = *allocation; | |
234 widget->allocation.x *= (1+vis->double_size); | |
235 widget->allocation.y *= (1+vis->double_size); | |
236 if (GTK_WIDGET_REALIZED (widget)) | |
3058
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
237 { |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
238 if (vis->event_window != NULL) |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
239 gdk_window_move_resize(vis->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
240 else |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
241 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); |
766a0fd12f7d
do not place GDK_INPUT_ONLY windows in widget->window, use a event_window field for them
Giacomo Lozito <james@develia.org>
parents:
3052
diff
changeset
|
242 } |
3020 | 243 |
244 vis->x = widget->allocation.x/(vis->double_size ? 2 : 1); | |
245 vis->y = widget->allocation.y/(vis->double_size ? 2 : 1); | |
246 } | |
247 | |
248 static gboolean ui_vis_expose(GtkWidget *widget, GdkEventExpose *event) { | |
249 g_return_val_if_fail (widget != NULL, FALSE); | |
250 g_return_val_if_fail (UI_IS_VIS (widget), FALSE); | |
251 g_return_val_if_fail (event != NULL, FALSE); | |
252 | |
253 UiVis *vis = UI_VIS (widget); | |
254 | |
255 gint x, y, n, h = 0, h2; | |
256 gfloat delta; | |
257 guchar skin_col[2][3]; | |
258 guchar vis_color[24][3]; | |
259 guchar vis_voice_color[256][3], voice_c[3]; | |
260 guchar rgb_data[76 * 16 * 3 * 2 * 2], *ptr, c; | |
261 guint32 colors[24]; | |
262 GdkColor *fgc, *bgc; | |
263 GdkRgbCmap *cmap; | |
264 | |
265 if (!GTK_WIDGET_VISIBLE(widget)) | |
266 return FALSE; | |
267 | |
268 if (!vis->visible_window) | |
269 return FALSE; | |
270 | |
271 skin_get_viscolor(bmp_active_skin, vis_color); | |
272 for (y = 0; y < 24; y++) { | |
273 colors[y] = | |
274 vis_color[y][0] << 16 | vis_color[y][1] << 8 | vis_color[y][2]; | |
275 } | |
276 cmap = gdk_rgb_cmap_new(colors, 24); | |
277 | |
278 if (!vis->double_size) { | |
279 if(cfg.vis_type == VIS_VOICEPRINT /*&& cfg.voiceprint_mode != VOICEPRINT_NORMAL*/){ | |
280 memset(rgb_data, 0, 76 * 16 * 3); | |
281 } | |
282 else{ | |
283 memset(rgb_data, 0, 76 * 16); | |
284 for (y = 1; y < 16; y += 2) { | |
285 ptr = rgb_data + (y * 76); | |
286 for (x = 0; x < 76; x += 2, ptr += 2) | |
287 *ptr = 1; | |
288 } | |
289 } | |
290 } | |
291 else{ | |
292 if(cfg.vis_type == VIS_VOICEPRINT /*&& cfg.voiceprint_mode != VOICEPRINT_NORMAL*/){ | |
293 memset(rgb_data, 0, 3 * 4 * 16 * 76); | |
294 } | |
295 else{ | |
296 memset(rgb_data, 0, 152 * 32); | |
297 for (y = 1; y < 16; y += 2) { | |
298 ptr = rgb_data + (y * 304); | |
299 for (x = 0; x < 76; x += 2, ptr += 4) { | |
300 *ptr = 1; | |
301 *(ptr + 1) = 1; | |
302 *(ptr + 152) = 1; | |
303 *(ptr + 153) = 1; | |
304 } | |
305 } | |
306 } | |
307 } | |
308 if (cfg.vis_type == VIS_ANALYZER) { | |
309 for (x = 0; x < 75; x++) { | |
310 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0) | |
311 h = vis->data[x >> 2]; | |
312 else if (cfg.analyzer_type == ANALYZER_LINES) | |
313 h = vis->data[x]; | |
314 if (h && (cfg.analyzer_type == ANALYZER_LINES || | |
315 (x % 4) != 3)) { | |
316 if (!vis->double_size) { | |
317 ptr = rgb_data + ((16 - h) * 76) + x; | |
318 switch (cfg.analyzer_mode) { | |
319 case ANALYZER_NORMAL: | |
320 for (y = 0; y < h; y++, ptr += 76) | |
321 *ptr = 18 - h + y; | |
322 break; | |
323 case ANALYZER_FIRE: | |
324 for (y = 0; y < h; y++, ptr += 76) | |
325 *ptr = y + 2; | |
326 break; | |
327 case ANALYZER_VLINES: | |
328 for (y = 0; y < h; y++, ptr += 76) | |
329 *ptr = 18 - h; | |
330 break; | |
331 } | |
332 } | |
333 else{ | |
334 ptr = rgb_data + ((16 - h) * 304) + (x << 1); | |
335 switch (cfg.analyzer_mode) { | |
336 case ANALYZER_NORMAL: | |
337 for (y = 0; y < h; y++, ptr += 304) { | |
338 *ptr = 18 - h + y; | |
339 *(ptr + 1) = 18 - h + y; | |
340 *(ptr + 152) = 18 - h + y; | |
341 *(ptr + 153) = 18 - h + y; | |
342 } | |
343 break; | |
344 case ANALYZER_FIRE: | |
345 for (y = 0; y < h; y++, ptr += 304) { | |
346 *ptr = y + 2; | |
347 *(ptr + 1) = y + 2; | |
348 *(ptr + 152) = y + 2; | |
349 *(ptr + 153) = y + 2; | |
350 } | |
351 break; | |
352 case ANALYZER_VLINES: | |
353 for (y = 0; y < h; y++, ptr += 304) { | |
354 *ptr = 18 - h; | |
355 *(ptr + 1) = 18 - h; | |
356 *(ptr + 152) = 18 - h; | |
357 *(ptr + 153) = 18 - h; | |
358 } | |
359 | |
360 break; | |
361 } | |
362 } | |
363 } | |
364 } | |
365 if (cfg.analyzer_peaks) { | |
366 for (x = 0; x < 75; x++) { | |
367 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0) | |
368 h = vis->peak[x >> 2]; | |
369 else if (cfg.analyzer_type == ANALYZER_LINES) | |
370 h = vis->peak[x]; | |
371 if (h && (cfg.analyzer_type == ANALYZER_LINES || (x % 4) != 3)){ | |
372 | |
373 if (!vis->double_size) { | |
374 rgb_data[(16 - h) * 76 + x] = 23; | |
375 } | |
376 else{ | |
377 ptr = rgb_data + (16 - h) * 304 + (x << 1); | |
378 *ptr = 23; | |
379 *(ptr + 1) = 23; | |
380 *(ptr + 152) = 23; | |
381 *(ptr + 153) = 23; | |
382 } | |
383 } | |
384 } | |
385 } | |
386 } | |
387 else if (cfg.vis_type == VIS_VOICEPRINT) { | |
388 if(!playback_get_paused() && playback_get_playing()){/*Don't scroll when it's paused or stopped*/ | |
389 for (y = 0; y < 16; y ++) | |
390 for (x = 75; x > 0; x--) | |
391 voiceprint_data[x + y * 76] = voiceprint_data[x-1+y*76]; | |
392 for(y=0;y<16;y++) | |
393 voiceprint_data[y * 76] = vis->data[y]; | |
394 } | |
395 if(playback_get_playing()){ /*Only draw the data if we're playing*/ | |
396 if(cfg.voiceprint_mode == VOICEPRINT_NORMAL){ | |
397 /* Create color gradient from the skin's background- and foreground color*/ | |
398 fgc = skin_get_color(bmp_active_skin, SKIN_TEXTFG); | |
399 bgc = skin_get_color(bmp_active_skin, SKIN_TEXTBG); | |
400 skin_col[0][0] = fgc->red >> 8; | |
401 skin_col[0][1] = fgc->green >> 8; | |
402 skin_col[0][2] = fgc->blue >> 8; | |
403 skin_col[1][0] = bgc->red >> 8; | |
404 skin_col[1][1] = bgc->green >> 8; | |
405 skin_col[1][2] = bgc->blue >> 8; | |
406 for(n=0;n<3;n++){ | |
407 for(x=0;x<256;x++){ | |
408 if(skin_col[0][n] > skin_col[1][n]){ | |
409 delta = (gfloat)(skin_col[0][n] - skin_col[1][n]) / 256.0; | |
410 vis_voice_color[x][n] = skin_col[1][n] + (gfloat)(delta * x); | |
411 } | |
412 else if(skin_col[0][n] == skin_col[1][n]){ | |
413 vis_voice_color[x][n] = skin_col[0][n]; | |
414 } | |
415 else{ | |
416 delta = (gfloat)(skin_col[1][n] - skin_col[0][n]) / 256.0; | |
417 vis_voice_color[x][n] = skin_col[1][n] - (gfloat)(delta * x); | |
418 } | |
419 } | |
420 } | |
421 } | |
422 for (y = 0; y < 16; y ++){ | |
423 for (x = 0; x < 76; x++){ | |
424 guint8 d = voiceprint_data[x + y*76]; | |
425 | |
426 if(cfg.voiceprint_mode == VOICEPRINT_NORMAL){ | |
427 voice_c[0] = vis_voice_color[d][0]; | |
428 voice_c[1] = vis_voice_color[d][1]; | |
429 voice_c[2] = vis_voice_color[d][2]; | |
430 } | |
431 else if(cfg.voiceprint_mode == VOICEPRINT_FIRE){ | |
432 voice_c[0] = d < 64 ? (d * 2) : 255; | |
433 voice_c[1] = d < 64 ? 0 : (d < 128 ? (d-64) * 2 : 255); | |
434 voice_c[2] = d < 128 ? 0 : (d-128) * 2; | |
435 /* Test for black->blue->green->red. Isn't pretty, though... | |
436 voice_c[0] = d > 192 ? (d - 192) << 2 : 0; | |
437 voice_c[1] = d > 64 ? (d < 128 ? (d - 64) << 2 : (d < 192 ? (192 - d) << 2 : 0)) : 0; | |
438 voice_c[2] = d < 64 ? d << 2 : (d < 128 ? (128 - d) << 2 : 0); | |
439 */ | |
440 } | |
441 else if(cfg.voiceprint_mode == VOICEPRINT_ICE){ | |
442 voice_c[0] = d; | |
443 voice_c[1] = d < 128 ? d * 2 : 255; | |
444 voice_c[2] = d < 64 ? d * 4 : 255; | |
445 } | |
446 if(!vis->double_size){ | |
447 for(n=0;n<3;n++) | |
448 rgb_data[x * 3 + y * 76*3+n] = voice_c[n]; | |
449 } | |
450 else{ | |
451 ptr = rgb_data + x * 3 * 2 + y * 2 * 76 * 3 * 2; | |
452 for(n=0;n<3;n++) | |
453 { | |
454 *(ptr + n) = voice_c[n]; | |
455 *(ptr + n + 3) = voice_c[n]; | |
456 *(ptr + n + 76 * 2 * 3) = voice_c[n]; | |
457 *(ptr + n + 3 + 76 * 2 * 3) = voice_c[n]; | |
458 } | |
459 } | |
460 } | |
461 } | |
462 } | |
463 } | |
464 if (cfg.vis_type == VIS_SCOPE) { | |
465 for (x = 0; x < 75; x++) { | |
466 switch (cfg.scope_mode) { | |
467 case SCOPE_DOT: | |
468 h = vis->data[x]; | |
469 if (!vis->double_size) { | |
470 ptr = rgb_data + ((14 - h) * 76) + x; | |
471 *ptr = vis_scope_colors[h + 1]; | |
472 }else{ | |
473 ptr = rgb_data + ((14 - h) * 304) + (x << 1); | |
474 *ptr = vis_scope_colors[h + 1]; | |
475 *(ptr + 1) = vis_scope_colors[h + 1]; | |
476 *(ptr + 152) = vis_scope_colors[h + 1]; | |
477 *(ptr + 153) = vis_scope_colors[h + 1]; | |
478 } | |
479 break; | |
480 case SCOPE_LINE: | |
481 if (x != 74) { | |
482 h = 14 - vis->data[x]; | |
483 h2 = 14 - vis->data[x + 1]; | |
484 if (h > h2) { | |
485 y = h; | |
486 h = h2; | |
487 h2 = y; | |
488 } | |
489 if (!vis->double_size) { | |
490 ptr = rgb_data + (h * 76) + x; | |
491 for (y = h; y <= h2; y++, ptr += 76) | |
492 *ptr = vis_scope_colors[y - 2]; | |
493 } | |
494 else{ | |
495 ptr = rgb_data + (h * 304) + (x << 1); | |
496 for (y = h; y <= h2; y++, ptr += 304) { | |
497 *ptr = vis_scope_colors[y - 2]; | |
498 *(ptr + 1) = vis_scope_colors[y - 2]; | |
499 *(ptr + 152) = vis_scope_colors[y - 2]; | |
500 *(ptr + 153) = vis_scope_colors[y - 2]; | |
501 } | |
502 } | |
503 } | |
504 else { | |
505 h = 14 - vis->data[x]; | |
506 if (!vis->double_size) { | |
507 ptr = rgb_data + (h * 76) + x; | |
508 *ptr = vis_scope_colors[h + 1]; | |
509 }else{ | |
510 ptr = rgb_data + (h * 304) + (x << 1); | |
511 *ptr = vis_scope_colors[h + 1]; | |
512 *(ptr + 1) = vis_scope_colors[h + 1]; | |
513 *(ptr + 152) = vis_scope_colors[h + 1]; | |
514 *(ptr + 153) = vis_scope_colors[h + 1]; | |
515 } | |
516 } | |
517 break; | |
518 case SCOPE_SOLID: | |
519 h = 14 - vis->data[x]; | |
520 h2 = 8; | |
521 c = vis_scope_colors[(gint) vis->data[x]]; | |
522 if (h > h2) { | |
523 y = h; | |
524 h = h2; | |
525 h2 = y; | |
526 } | |
527 if (!vis->double_size) { | |
528 ptr = rgb_data + (h * 76) + x; | |
529 for (y = h; y <= h2; y++, ptr += 76) | |
530 *ptr = c; | |
531 }else{ | |
532 ptr = rgb_data + (h * 304) + (x << 1); | |
533 for (y = h; y <= h2; y++, ptr += 304) { | |
534 *ptr = c; | |
535 *(ptr + 1) = c; | |
536 *(ptr + 152) = c; | |
537 *(ptr + 153) = c; | |
538 } | |
539 } | |
540 break; | |
541 } | |
542 } | |
543 } | |
544 | |
545 GdkPixmap *obj = NULL; | |
546 GdkGC *gc; | |
547 obj = gdk_pixmap_new(NULL, vis->width*(1+vis->double_size), vis->height*(1+vis->double_size), gdk_rgb_get_visual()->depth); | |
548 gc = gdk_gc_new(obj); | |
549 | |
550 if (!vis->double_size) { | |
551 if (cfg.vis_type == VIS_VOICEPRINT) { | |
552 gdk_draw_rgb_image(obj, gc, 0, 0, vis->width, vis->height, | |
553 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data, | |
554 76 * 3); | |
555 } else { | |
556 gdk_draw_indexed_image(obj, gc, 0, 0, vis->width, vis->height, | |
557 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data, | |
558 76 , cmap); | |
559 } | |
560 } else { | |
561 if (cfg.vis_type == VIS_VOICEPRINT) { | |
562 gdk_draw_rgb_image(obj, gc, 0 << 1, 0 << 1, | |
563 vis->width << 1, vis->height << 1, | |
564 GDK_RGB_DITHER_NONE, (guchar *) rgb_data, | |
565 76 * 2 * 3); | |
566 } else { | |
567 gdk_draw_indexed_image(obj, gc, 0 << 1, 0 << 1, | |
568 vis->width << 1, vis->height << 1, | |
569 GDK_RGB_DITHER_NONE, (guchar *) rgb_data, | |
570 76 * 2 , cmap); | |
571 } | |
572 } | |
573 | |
574 gdk_draw_drawable (widget->window, gc, obj, 0, 0, 0, 0, | |
575 vis->width*(1+vis->double_size), vis->height*(1+vis->double_size)); | |
576 g_object_unref(obj); | |
577 g_object_unref(gc); | |
578 gdk_rgb_cmap_free(cmap); | |
579 return FALSE; | |
580 } | |
581 | |
582 static void ui_vis_toggle_doublesize(UiVis *vis) { | |
583 GtkWidget *widget = GTK_WIDGET (vis); | |
584 vis->double_size = !vis->double_size; | |
585 | |
586 gtk_widget_set_size_request(widget, vis->width*(1+vis->double_size), vis->height*(1+vis->double_size)); | |
587 | |
588 gtk_widget_queue_draw(GTK_WIDGET(vis)); | |
589 } | |
590 | |
591 void ui_vis_draw_pixel(GtkWidget *widget, guchar* texture, gint x, gint y, guint8 colour) { | |
592 UiVis *vis = UI_VIS (widget); | |
593 if (vis->double_size){ | |
594 texture[y * 76 + x] = colour; | |
595 texture[y * 76 + x + 1] = colour; | |
596 texture[y * 76 * 4 + x] = colour; | |
597 texture[y * 76 * 4 + x + 1] = colour; | |
598 } else { | |
599 texture[y * 76 + x] = colour; | |
600 } | |
601 } | |
602 | |
603 void ui_vis_set_visible(GtkWidget *widget, gboolean window_is_visible) | |
604 { | |
605 UiVis *vis; | |
606 gboolean widget_is_visible; | |
607 | |
608 g_return_if_fail(UI_IS_VIS(widget)); | |
609 | |
610 vis = UI_VIS (widget); | |
611 widget_is_visible = GTK_WIDGET_VISIBLE(widget); | |
612 | |
613 vis->visible_window = window_is_visible; | |
614 | |
615 if (GTK_WIDGET_REALIZED (widget)) | |
616 { | |
617 if ( widget_is_visible ) | |
618 gtk_widget_hide(widget); | |
619 | |
620 gtk_widget_unrealize(widget); | |
621 gtk_widget_realize(widget); | |
622 | |
623 if ( widget_is_visible ) | |
624 gtk_widget_show(widget); | |
625 } | |
626 | |
627 if (widget_is_visible) | |
628 gtk_widget_queue_resize(widget); | |
629 } | |
630 | |
631 void ui_vis_clear_data(GtkWidget *widget) { | |
632 gint i; | |
633 UiVis *vis = UI_VIS (widget); | |
634 | |
635 memset(voiceprint_data, 0, 16*76); | |
636 for (i = 0; i < 75; i++) { | |
637 vis->data[i] = (cfg.vis_type == VIS_SCOPE) ? 6 : 0; | |
638 vis->peak[i] = 0; | |
639 } | |
640 } | |
641 | |
642 void ui_vis_timeout_func(GtkWidget *widget, guchar * data) { | |
643 UiVis *vis = UI_VIS (widget); | |
644 static GTimer *timer = NULL; | |
645 gulong micros = 9999999; | |
646 gboolean falloff = FALSE; | |
647 gint i; | |
648 | |
649 if (!timer) { | |
650 timer = g_timer_new(); | |
651 g_timer_start(timer); | |
652 } | |
653 else { | |
654 g_timer_elapsed(timer, µs); | |
655 if (micros > 14000) | |
656 g_timer_reset(timer); | |
657 } | |
658 if (cfg.vis_type == VIS_ANALYZER) { | |
659 if (micros > 14000) | |
660 falloff = TRUE; | |
661 if (data || falloff) { | |
662 for (i = 0; i < 75; i++) { | |
663 if (data && data[i] > vis->data[i]) { | |
664 vis->data[i] = data[i]; | |
665 if (vis->data[i] > vis->peak[i]) { | |
666 vis->peak[i] = vis->data[i]; | |
667 vis->peak_speed[i] = 0.01; | |
668 | |
669 } | |
670 else if (vis->peak[i] > 0.0) { | |
671 vis->peak[i] -= vis->peak_speed[i]; | |
672 vis->peak_speed[i] *= | |
673 vis_pfalloff_speeds[cfg.peaks_falloff]; | |
674 if (vis->peak[i] < vis->data[i]) | |
675 vis->peak[i] = vis->data[i]; | |
676 if (vis->peak[i] < 0.0) | |
677 vis->peak[i] = 0.0; | |
678 } | |
679 } | |
680 else if (falloff) { | |
681 if (vis->data[i] > 0.0) { | |
682 vis->data[i] -= | |
683 vis_afalloff_speeds[cfg.analyzer_falloff]; | |
684 if (vis->data[i] < 0.0) | |
685 vis->data[i] = 0.0; | |
686 } | |
687 if (vis->peak[i] > 0.0) { | |
688 vis->peak[i] -= vis->peak_speed[i]; | |
689 vis->peak_speed[i] *= | |
690 vis_pfalloff_speeds[cfg.peaks_falloff]; | |
691 if (vis->peak[i] < vis->data[i]) | |
692 vis->peak[i] = vis->data[i]; | |
693 if (vis->peak[i] < 0.0) | |
694 vis->peak[i] = 0.0; | |
695 } | |
696 } | |
697 } | |
698 } | |
699 } | |
700 else if (cfg.vis_type == VIS_VOICEPRINT && data){ | |
701 for(i = 0; i < 16; i++) | |
702 { | |
703 vis->data[i] = data[15 - i]; | |
704 } | |
705 } | |
706 else if (data) { | |
707 for (i = 0; i < 75; i++) | |
708 vis->data[i] = data[i]; | |
709 } | |
710 | |
711 if (micros > 14000) { | |
712 if (!vis->refresh_delay) { | |
713 gtk_widget_queue_draw(widget); | |
714 vis->refresh_delay = vis_redraw_delays[cfg.vis_refresh]; | |
715 } | |
716 vis->refresh_delay--; | |
717 } | |
718 } |