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