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