|
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);
|
|
3052
|
169 GTK_WIDGET_UNSET_FLAGS(widget, GTK_NO_WINDOW);
|
|
3020
|
170 }
|
|
|
171 else
|
|
|
172 {
|
|
|
173 attributes.wclass = GDK_INPUT_ONLY;
|
|
|
174 attributes_mask = GDK_WA_X | GDK_WA_Y;
|
|
|
175 widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
|
|
3052
|
176 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
|
|
3020
|
177 }
|
|
|
178
|
|
|
179 widget->style = gtk_style_attach(widget->style, widget->window);
|
|
|
180
|
|
|
181 gdk_window_set_user_data(widget->window, widget);
|
|
3052
|
182
|
|
|
183 if (attributes.wclass == GDK_INPUT_ONLY)
|
|
|
184 gdk_window_show (widget->window);
|
|
3020
|
185 }
|
|
|
186
|
|
|
187 static void ui_vis_unrealize(GtkWidget *widget) {
|
|
|
188 UiVis *vis;
|
|
|
189 vis = UI_VIS(widget);
|
|
|
190
|
|
|
191 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
|
|
192 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
|
|
193 }
|
|
|
194
|
|
|
195 static void ui_vis_size_request(GtkWidget *widget, GtkRequisition *requisition) {
|
|
|
196 UiVis *vis = UI_VIS(widget);
|
|
|
197
|
|
|
198 requisition->width = vis->width*(1+vis->double_size);
|
|
|
199 requisition->height = vis->height*(1+vis->double_size);
|
|
|
200 }
|
|
|
201
|
|
|
202 static void ui_vis_size_allocate(GtkWidget *widget, GtkAllocation *allocation) {
|
|
|
203 UiVis *vis = UI_VIS (widget);
|
|
|
204
|
|
|
205 widget->allocation = *allocation;
|
|
|
206 widget->allocation.x *= (1+vis->double_size);
|
|
|
207 widget->allocation.y *= (1+vis->double_size);
|
|
|
208 if (GTK_WIDGET_REALIZED (widget))
|
|
|
209 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
|
|
|
210
|
|
|
211 vis->x = widget->allocation.x/(vis->double_size ? 2 : 1);
|
|
|
212 vis->y = widget->allocation.y/(vis->double_size ? 2 : 1);
|
|
|
213 }
|
|
|
214
|
|
|
215 static gboolean ui_vis_expose(GtkWidget *widget, GdkEventExpose *event) {
|
|
|
216 g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
217 g_return_val_if_fail (UI_IS_VIS (widget), FALSE);
|
|
|
218 g_return_val_if_fail (event != NULL, FALSE);
|
|
|
219
|
|
|
220 UiVis *vis = UI_VIS (widget);
|
|
|
221
|
|
|
222 gint x, y, n, h = 0, h2;
|
|
|
223 gfloat delta;
|
|
|
224 guchar skin_col[2][3];
|
|
|
225 guchar vis_color[24][3];
|
|
|
226 guchar vis_voice_color[256][3], voice_c[3];
|
|
|
227 guchar rgb_data[76 * 16 * 3 * 2 * 2], *ptr, c;
|
|
|
228 guint32 colors[24];
|
|
|
229 GdkColor *fgc, *bgc;
|
|
|
230 GdkRgbCmap *cmap;
|
|
|
231
|
|
|
232 if (!GTK_WIDGET_VISIBLE(widget))
|
|
|
233 return FALSE;
|
|
|
234
|
|
|
235 if (!vis->visible_window)
|
|
|
236 return FALSE;
|
|
|
237
|
|
|
238 skin_get_viscolor(bmp_active_skin, vis_color);
|
|
|
239 for (y = 0; y < 24; y++) {
|
|
|
240 colors[y] =
|
|
|
241 vis_color[y][0] << 16 | vis_color[y][1] << 8 | vis_color[y][2];
|
|
|
242 }
|
|
|
243 cmap = gdk_rgb_cmap_new(colors, 24);
|
|
|
244
|
|
|
245 if (!vis->double_size) {
|
|
|
246 if(cfg.vis_type == VIS_VOICEPRINT /*&& cfg.voiceprint_mode != VOICEPRINT_NORMAL*/){
|
|
|
247 memset(rgb_data, 0, 76 * 16 * 3);
|
|
|
248 }
|
|
|
249 else{
|
|
|
250 memset(rgb_data, 0, 76 * 16);
|
|
|
251 for (y = 1; y < 16; y += 2) {
|
|
|
252 ptr = rgb_data + (y * 76);
|
|
|
253 for (x = 0; x < 76; x += 2, ptr += 2)
|
|
|
254 *ptr = 1;
|
|
|
255 }
|
|
|
256 }
|
|
|
257 }
|
|
|
258 else{
|
|
|
259 if(cfg.vis_type == VIS_VOICEPRINT /*&& cfg.voiceprint_mode != VOICEPRINT_NORMAL*/){
|
|
|
260 memset(rgb_data, 0, 3 * 4 * 16 * 76);
|
|
|
261 }
|
|
|
262 else{
|
|
|
263 memset(rgb_data, 0, 152 * 32);
|
|
|
264 for (y = 1; y < 16; y += 2) {
|
|
|
265 ptr = rgb_data + (y * 304);
|
|
|
266 for (x = 0; x < 76; x += 2, ptr += 4) {
|
|
|
267 *ptr = 1;
|
|
|
268 *(ptr + 1) = 1;
|
|
|
269 *(ptr + 152) = 1;
|
|
|
270 *(ptr + 153) = 1;
|
|
|
271 }
|
|
|
272 }
|
|
|
273 }
|
|
|
274 }
|
|
|
275 if (cfg.vis_type == VIS_ANALYZER) {
|
|
|
276 for (x = 0; x < 75; x++) {
|
|
|
277 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0)
|
|
|
278 h = vis->data[x >> 2];
|
|
|
279 else if (cfg.analyzer_type == ANALYZER_LINES)
|
|
|
280 h = vis->data[x];
|
|
|
281 if (h && (cfg.analyzer_type == ANALYZER_LINES ||
|
|
|
282 (x % 4) != 3)) {
|
|
|
283 if (!vis->double_size) {
|
|
|
284 ptr = rgb_data + ((16 - h) * 76) + x;
|
|
|
285 switch (cfg.analyzer_mode) {
|
|
|
286 case ANALYZER_NORMAL:
|
|
|
287 for (y = 0; y < h; y++, ptr += 76)
|
|
|
288 *ptr = 18 - h + y;
|
|
|
289 break;
|
|
|
290 case ANALYZER_FIRE:
|
|
|
291 for (y = 0; y < h; y++, ptr += 76)
|
|
|
292 *ptr = y + 2;
|
|
|
293 break;
|
|
|
294 case ANALYZER_VLINES:
|
|
|
295 for (y = 0; y < h; y++, ptr += 76)
|
|
|
296 *ptr = 18 - h;
|
|
|
297 break;
|
|
|
298 }
|
|
|
299 }
|
|
|
300 else{
|
|
|
301 ptr = rgb_data + ((16 - h) * 304) + (x << 1);
|
|
|
302 switch (cfg.analyzer_mode) {
|
|
|
303 case ANALYZER_NORMAL:
|
|
|
304 for (y = 0; y < h; y++, ptr += 304) {
|
|
|
305 *ptr = 18 - h + y;
|
|
|
306 *(ptr + 1) = 18 - h + y;
|
|
|
307 *(ptr + 152) = 18 - h + y;
|
|
|
308 *(ptr + 153) = 18 - h + y;
|
|
|
309 }
|
|
|
310 break;
|
|
|
311 case ANALYZER_FIRE:
|
|
|
312 for (y = 0; y < h; y++, ptr += 304) {
|
|
|
313 *ptr = y + 2;
|
|
|
314 *(ptr + 1) = y + 2;
|
|
|
315 *(ptr + 152) = y + 2;
|
|
|
316 *(ptr + 153) = y + 2;
|
|
|
317 }
|
|
|
318 break;
|
|
|
319 case ANALYZER_VLINES:
|
|
|
320 for (y = 0; y < h; y++, ptr += 304) {
|
|
|
321 *ptr = 18 - h;
|
|
|
322 *(ptr + 1) = 18 - h;
|
|
|
323 *(ptr + 152) = 18 - h;
|
|
|
324 *(ptr + 153) = 18 - h;
|
|
|
325 }
|
|
|
326
|
|
|
327 break;
|
|
|
328 }
|
|
|
329 }
|
|
|
330 }
|
|
|
331 }
|
|
|
332 if (cfg.analyzer_peaks) {
|
|
|
333 for (x = 0; x < 75; x++) {
|
|
|
334 if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0)
|
|
|
335 h = vis->peak[x >> 2];
|
|
|
336 else if (cfg.analyzer_type == ANALYZER_LINES)
|
|
|
337 h = vis->peak[x];
|
|
|
338 if (h && (cfg.analyzer_type == ANALYZER_LINES || (x % 4) != 3)){
|
|
|
339
|
|
|
340 if (!vis->double_size) {
|
|
|
341 rgb_data[(16 - h) * 76 + x] = 23;
|
|
|
342 }
|
|
|
343 else{
|
|
|
344 ptr = rgb_data + (16 - h) * 304 + (x << 1);
|
|
|
345 *ptr = 23;
|
|
|
346 *(ptr + 1) = 23;
|
|
|
347 *(ptr + 152) = 23;
|
|
|
348 *(ptr + 153) = 23;
|
|
|
349 }
|
|
|
350 }
|
|
|
351 }
|
|
|
352 }
|
|
|
353 }
|
|
|
354 else if (cfg.vis_type == VIS_VOICEPRINT) {
|
|
|
355 if(!playback_get_paused() && playback_get_playing()){/*Don't scroll when it's paused or stopped*/
|
|
|
356 for (y = 0; y < 16; y ++)
|
|
|
357 for (x = 75; x > 0; x--)
|
|
|
358 voiceprint_data[x + y * 76] = voiceprint_data[x-1+y*76];
|
|
|
359 for(y=0;y<16;y++)
|
|
|
360 voiceprint_data[y * 76] = vis->data[y];
|
|
|
361 }
|
|
|
362 if(playback_get_playing()){ /*Only draw the data if we're playing*/
|
|
|
363 if(cfg.voiceprint_mode == VOICEPRINT_NORMAL){
|
|
|
364 /* Create color gradient from the skin's background- and foreground color*/
|
|
|
365 fgc = skin_get_color(bmp_active_skin, SKIN_TEXTFG);
|
|
|
366 bgc = skin_get_color(bmp_active_skin, SKIN_TEXTBG);
|
|
|
367 skin_col[0][0] = fgc->red >> 8;
|
|
|
368 skin_col[0][1] = fgc->green >> 8;
|
|
|
369 skin_col[0][2] = fgc->blue >> 8;
|
|
|
370 skin_col[1][0] = bgc->red >> 8;
|
|
|
371 skin_col[1][1] = bgc->green >> 8;
|
|
|
372 skin_col[1][2] = bgc->blue >> 8;
|
|
|
373 for(n=0;n<3;n++){
|
|
|
374 for(x=0;x<256;x++){
|
|
|
375 if(skin_col[0][n] > skin_col[1][n]){
|
|
|
376 delta = (gfloat)(skin_col[0][n] - skin_col[1][n]) / 256.0;
|
|
|
377 vis_voice_color[x][n] = skin_col[1][n] + (gfloat)(delta * x);
|
|
|
378 }
|
|
|
379 else if(skin_col[0][n] == skin_col[1][n]){
|
|
|
380 vis_voice_color[x][n] = skin_col[0][n];
|
|
|
381 }
|
|
|
382 else{
|
|
|
383 delta = (gfloat)(skin_col[1][n] - skin_col[0][n]) / 256.0;
|
|
|
384 vis_voice_color[x][n] = skin_col[1][n] - (gfloat)(delta * x);
|
|
|
385 }
|
|
|
386 }
|
|
|
387 }
|
|
|
388 }
|
|
|
389 for (y = 0; y < 16; y ++){
|
|
|
390 for (x = 0; x < 76; x++){
|
|
|
391 guint8 d = voiceprint_data[x + y*76];
|
|
|
392
|
|
|
393 if(cfg.voiceprint_mode == VOICEPRINT_NORMAL){
|
|
|
394 voice_c[0] = vis_voice_color[d][0];
|
|
|
395 voice_c[1] = vis_voice_color[d][1];
|
|
|
396 voice_c[2] = vis_voice_color[d][2];
|
|
|
397 }
|
|
|
398 else if(cfg.voiceprint_mode == VOICEPRINT_FIRE){
|
|
|
399 voice_c[0] = d < 64 ? (d * 2) : 255;
|
|
|
400 voice_c[1] = d < 64 ? 0 : (d < 128 ? (d-64) * 2 : 255);
|
|
|
401 voice_c[2] = d < 128 ? 0 : (d-128) * 2;
|
|
|
402 /* Test for black->blue->green->red. Isn't pretty, though...
|
|
|
403 voice_c[0] = d > 192 ? (d - 192) << 2 : 0;
|
|
|
404 voice_c[1] = d > 64 ? (d < 128 ? (d - 64) << 2 : (d < 192 ? (192 - d) << 2 : 0)) : 0;
|
|
|
405 voice_c[2] = d < 64 ? d << 2 : (d < 128 ? (128 - d) << 2 : 0);
|
|
|
406 */
|
|
|
407 }
|
|
|
408 else if(cfg.voiceprint_mode == VOICEPRINT_ICE){
|
|
|
409 voice_c[0] = d;
|
|
|
410 voice_c[1] = d < 128 ? d * 2 : 255;
|
|
|
411 voice_c[2] = d < 64 ? d * 4 : 255;
|
|
|
412 }
|
|
|
413 if(!vis->double_size){
|
|
|
414 for(n=0;n<3;n++)
|
|
|
415 rgb_data[x * 3 + y * 76*3+n] = voice_c[n];
|
|
|
416 }
|
|
|
417 else{
|
|
|
418 ptr = rgb_data + x * 3 * 2 + y * 2 * 76 * 3 * 2;
|
|
|
419 for(n=0;n<3;n++)
|
|
|
420 {
|
|
|
421 *(ptr + n) = voice_c[n];
|
|
|
422 *(ptr + n + 3) = voice_c[n];
|
|
|
423 *(ptr + n + 76 * 2 * 3) = voice_c[n];
|
|
|
424 *(ptr + n + 3 + 76 * 2 * 3) = voice_c[n];
|
|
|
425 }
|
|
|
426 }
|
|
|
427 }
|
|
|
428 }
|
|
|
429 }
|
|
|
430 }
|
|
|
431 if (cfg.vis_type == VIS_SCOPE) {
|
|
|
432 for (x = 0; x < 75; x++) {
|
|
|
433 switch (cfg.scope_mode) {
|
|
|
434 case SCOPE_DOT:
|
|
|
435 h = vis->data[x];
|
|
|
436 if (!vis->double_size) {
|
|
|
437 ptr = rgb_data + ((14 - h) * 76) + x;
|
|
|
438 *ptr = vis_scope_colors[h + 1];
|
|
|
439 }else{
|
|
|
440 ptr = rgb_data + ((14 - h) * 304) + (x << 1);
|
|
|
441 *ptr = vis_scope_colors[h + 1];
|
|
|
442 *(ptr + 1) = vis_scope_colors[h + 1];
|
|
|
443 *(ptr + 152) = vis_scope_colors[h + 1];
|
|
|
444 *(ptr + 153) = vis_scope_colors[h + 1];
|
|
|
445 }
|
|
|
446 break;
|
|
|
447 case SCOPE_LINE:
|
|
|
448 if (x != 74) {
|
|
|
449 h = 14 - vis->data[x];
|
|
|
450 h2 = 14 - vis->data[x + 1];
|
|
|
451 if (h > h2) {
|
|
|
452 y = h;
|
|
|
453 h = h2;
|
|
|
454 h2 = y;
|
|
|
455 }
|
|
|
456 if (!vis->double_size) {
|
|
|
457 ptr = rgb_data + (h * 76) + x;
|
|
|
458 for (y = h; y <= h2; y++, ptr += 76)
|
|
|
459 *ptr = vis_scope_colors[y - 2];
|
|
|
460 }
|
|
|
461 else{
|
|
|
462 ptr = rgb_data + (h * 304) + (x << 1);
|
|
|
463 for (y = h; y <= h2; y++, ptr += 304) {
|
|
|
464 *ptr = vis_scope_colors[y - 2];
|
|
|
465 *(ptr + 1) = vis_scope_colors[y - 2];
|
|
|
466 *(ptr + 152) = vis_scope_colors[y - 2];
|
|
|
467 *(ptr + 153) = vis_scope_colors[y - 2];
|
|
|
468 }
|
|
|
469 }
|
|
|
470 }
|
|
|
471 else {
|
|
|
472 h = 14 - vis->data[x];
|
|
|
473 if (!vis->double_size) {
|
|
|
474 ptr = rgb_data + (h * 76) + x;
|
|
|
475 *ptr = vis_scope_colors[h + 1];
|
|
|
476 }else{
|
|
|
477 ptr = rgb_data + (h * 304) + (x << 1);
|
|
|
478 *ptr = vis_scope_colors[h + 1];
|
|
|
479 *(ptr + 1) = vis_scope_colors[h + 1];
|
|
|
480 *(ptr + 152) = vis_scope_colors[h + 1];
|
|
|
481 *(ptr + 153) = vis_scope_colors[h + 1];
|
|
|
482 }
|
|
|
483 }
|
|
|
484 break;
|
|
|
485 case SCOPE_SOLID:
|
|
|
486 h = 14 - vis->data[x];
|
|
|
487 h2 = 8;
|
|
|
488 c = vis_scope_colors[(gint) vis->data[x]];
|
|
|
489 if (h > h2) {
|
|
|
490 y = h;
|
|
|
491 h = h2;
|
|
|
492 h2 = y;
|
|
|
493 }
|
|
|
494 if (!vis->double_size) {
|
|
|
495 ptr = rgb_data + (h * 76) + x;
|
|
|
496 for (y = h; y <= h2; y++, ptr += 76)
|
|
|
497 *ptr = c;
|
|
|
498 }else{
|
|
|
499 ptr = rgb_data + (h * 304) + (x << 1);
|
|
|
500 for (y = h; y <= h2; y++, ptr += 304) {
|
|
|
501 *ptr = c;
|
|
|
502 *(ptr + 1) = c;
|
|
|
503 *(ptr + 152) = c;
|
|
|
504 *(ptr + 153) = c;
|
|
|
505 }
|
|
|
506 }
|
|
|
507 break;
|
|
|
508 }
|
|
|
509 }
|
|
|
510 }
|
|
|
511
|
|
|
512 GdkPixmap *obj = NULL;
|
|
|
513 GdkGC *gc;
|
|
|
514 obj = gdk_pixmap_new(NULL, vis->width*(1+vis->double_size), vis->height*(1+vis->double_size), gdk_rgb_get_visual()->depth);
|
|
|
515 gc = gdk_gc_new(obj);
|
|
|
516
|
|
|
517 if (!vis->double_size) {
|
|
|
518 if (cfg.vis_type == VIS_VOICEPRINT) {
|
|
|
519 gdk_draw_rgb_image(obj, gc, 0, 0, vis->width, vis->height,
|
|
|
520 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data,
|
|
|
521 76 * 3);
|
|
|
522 } else {
|
|
|
523 gdk_draw_indexed_image(obj, gc, 0, 0, vis->width, vis->height,
|
|
|
524 GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data,
|
|
|
525 76 , cmap);
|
|
|
526 }
|
|
|
527 } else {
|
|
|
528 if (cfg.vis_type == VIS_VOICEPRINT) {
|
|
|
529 gdk_draw_rgb_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 * 3);
|
|
|
533 } else {
|
|
|
534 gdk_draw_indexed_image(obj, gc, 0 << 1, 0 << 1,
|
|
|
535 vis->width << 1, vis->height << 1,
|
|
|
536 GDK_RGB_DITHER_NONE, (guchar *) rgb_data,
|
|
|
537 76 * 2 , cmap);
|
|
|
538 }
|
|
|
539 }
|
|
|
540
|
|
|
541 gdk_draw_drawable (widget->window, gc, obj, 0, 0, 0, 0,
|
|
|
542 vis->width*(1+vis->double_size), vis->height*(1+vis->double_size));
|
|
|
543 g_object_unref(obj);
|
|
|
544 g_object_unref(gc);
|
|
|
545 gdk_rgb_cmap_free(cmap);
|
|
|
546 return FALSE;
|
|
|
547 }
|
|
|
548
|
|
|
549 static void ui_vis_toggle_doublesize(UiVis *vis) {
|
|
|
550 GtkWidget *widget = GTK_WIDGET (vis);
|
|
|
551 vis->double_size = !vis->double_size;
|
|
|
552
|
|
|
553 gtk_widget_set_size_request(widget, vis->width*(1+vis->double_size), vis->height*(1+vis->double_size));
|
|
|
554
|
|
|
555 gtk_widget_queue_draw(GTK_WIDGET(vis));
|
|
|
556 }
|
|
|
557
|
|
|
558 void ui_vis_draw_pixel(GtkWidget *widget, guchar* texture, gint x, gint y, guint8 colour) {
|
|
|
559 UiVis *vis = UI_VIS (widget);
|
|
|
560 if (vis->double_size){
|
|
|
561 texture[y * 76 + x] = colour;
|
|
|
562 texture[y * 76 + x + 1] = colour;
|
|
|
563 texture[y * 76 * 4 + x] = colour;
|
|
|
564 texture[y * 76 * 4 + x + 1] = colour;
|
|
|
565 } else {
|
|
|
566 texture[y * 76 + x] = colour;
|
|
|
567 }
|
|
|
568 }
|
|
|
569
|
|
|
570 void ui_vis_set_visible(GtkWidget *widget, gboolean window_is_visible)
|
|
|
571 {
|
|
|
572 UiVis *vis;
|
|
|
573 gboolean widget_is_visible;
|
|
|
574
|
|
|
575 g_return_if_fail(UI_IS_VIS(widget));
|
|
|
576
|
|
|
577 vis = UI_VIS (widget);
|
|
|
578 widget_is_visible = GTK_WIDGET_VISIBLE(widget);
|
|
|
579
|
|
|
580 vis->visible_window = window_is_visible;
|
|
|
581
|
|
|
582 if (GTK_WIDGET_REALIZED (widget))
|
|
|
583 {
|
|
|
584 if ( widget_is_visible )
|
|
|
585 gtk_widget_hide(widget);
|
|
|
586
|
|
|
587 gtk_widget_unrealize(widget);
|
|
|
588 gtk_widget_realize(widget);
|
|
|
589
|
|
|
590 if ( widget_is_visible )
|
|
|
591 gtk_widget_show(widget);
|
|
|
592 }
|
|
|
593
|
|
|
594 if (widget_is_visible)
|
|
|
595 gtk_widget_queue_resize(widget);
|
|
|
596 }
|
|
|
597
|
|
|
598 void ui_vis_clear_data(GtkWidget *widget) {
|
|
|
599 gint i;
|
|
|
600 UiVis *vis = UI_VIS (widget);
|
|
|
601
|
|
|
602 memset(voiceprint_data, 0, 16*76);
|
|
|
603 for (i = 0; i < 75; i++) {
|
|
|
604 vis->data[i] = (cfg.vis_type == VIS_SCOPE) ? 6 : 0;
|
|
|
605 vis->peak[i] = 0;
|
|
|
606 }
|
|
|
607 }
|
|
|
608
|
|
|
609 void ui_vis_timeout_func(GtkWidget *widget, guchar * data) {
|
|
|
610 UiVis *vis = UI_VIS (widget);
|
|
|
611 static GTimer *timer = NULL;
|
|
|
612 gulong micros = 9999999;
|
|
|
613 gboolean falloff = FALSE;
|
|
|
614 gint i;
|
|
|
615
|
|
|
616 if (!timer) {
|
|
|
617 timer = g_timer_new();
|
|
|
618 g_timer_start(timer);
|
|
|
619 }
|
|
|
620 else {
|
|
|
621 g_timer_elapsed(timer, µs);
|
|
|
622 if (micros > 14000)
|
|
|
623 g_timer_reset(timer);
|
|
|
624 }
|
|
|
625 if (cfg.vis_type == VIS_ANALYZER) {
|
|
|
626 if (micros > 14000)
|
|
|
627 falloff = TRUE;
|
|
|
628 if (data || falloff) {
|
|
|
629 for (i = 0; i < 75; i++) {
|
|
|
630 if (data && data[i] > vis->data[i]) {
|
|
|
631 vis->data[i] = data[i];
|
|
|
632 if (vis->data[i] > vis->peak[i]) {
|
|
|
633 vis->peak[i] = vis->data[i];
|
|
|
634 vis->peak_speed[i] = 0.01;
|
|
|
635
|
|
|
636 }
|
|
|
637 else if (vis->peak[i] > 0.0) {
|
|
|
638 vis->peak[i] -= vis->peak_speed[i];
|
|
|
639 vis->peak_speed[i] *=
|
|
|
640 vis_pfalloff_speeds[cfg.peaks_falloff];
|
|
|
641 if (vis->peak[i] < vis->data[i])
|
|
|
642 vis->peak[i] = vis->data[i];
|
|
|
643 if (vis->peak[i] < 0.0)
|
|
|
644 vis->peak[i] = 0.0;
|
|
|
645 }
|
|
|
646 }
|
|
|
647 else if (falloff) {
|
|
|
648 if (vis->data[i] > 0.0) {
|
|
|
649 vis->data[i] -=
|
|
|
650 vis_afalloff_speeds[cfg.analyzer_falloff];
|
|
|
651 if (vis->data[i] < 0.0)
|
|
|
652 vis->data[i] = 0.0;
|
|
|
653 }
|
|
|
654 if (vis->peak[i] > 0.0) {
|
|
|
655 vis->peak[i] -= vis->peak_speed[i];
|
|
|
656 vis->peak_speed[i] *=
|
|
|
657 vis_pfalloff_speeds[cfg.peaks_falloff];
|
|
|
658 if (vis->peak[i] < vis->data[i])
|
|
|
659 vis->peak[i] = vis->data[i];
|
|
|
660 if (vis->peak[i] < 0.0)
|
|
|
661 vis->peak[i] = 0.0;
|
|
|
662 }
|
|
|
663 }
|
|
|
664 }
|
|
|
665 }
|
|
|
666 }
|
|
|
667 else if (cfg.vis_type == VIS_VOICEPRINT && data){
|
|
|
668 for(i = 0; i < 16; i++)
|
|
|
669 {
|
|
|
670 vis->data[i] = data[15 - i];
|
|
|
671 }
|
|
|
672 }
|
|
|
673 else if (data) {
|
|
|
674 for (i = 0; i < 75; i++)
|
|
|
675 vis->data[i] = data[i];
|
|
|
676 }
|
|
|
677
|
|
|
678 if (micros > 14000) {
|
|
|
679 if (!vis->refresh_delay) {
|
|
|
680 gtk_widget_queue_draw(widget);
|
|
|
681 vis->refresh_delay = vis_redraw_delays[cfg.vis_refresh];
|
|
|
682 }
|
|
|
683 vis->refresh_delay--;
|
|
|
684 }
|
|
|
685 }
|