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