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