comparison src/audacious/ui_vis.c @ 3020:6065d70cb790 trunk

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