Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_equalizer_graph.c @ 3052:95b34f46a231
Comment out MPEG2/MPEG4 determination using the variable id. It is not used anywhere. Code analysis run, unique ID 6nYoHM.
author | Tony Vroon <chainsaw@gentoo.org> |
---|---|
date | Sat, 18 Apr 2009 19:06:20 +0100 |
parents | 6baa6eaf8290 |
children |
rev | line source |
---|---|
2591 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
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 | |
24 #include "ui_skin.h" | |
25 #include "ui_skinned_equalizer_graph.h" | |
26 #include "skins_cfg.h" | |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2888
diff
changeset
|
27 #include <audlegacy/plugin.h> |
2591 | 28 |
29 #define UI_TYPE_SKINNED_EQUALIZER_GRAPH (ui_skinned_equalizer_graph_get_type()) | |
30 | |
31 enum { | |
32 DOUBLED, | |
33 LAST_SIGNAL | |
34 }; | |
35 | |
36 static void ui_skinned_equalizer_graph_class_init (UiSkinnedEqualizerGraphClass *klass); | |
37 static void ui_skinned_equalizer_graph_init (UiSkinnedEqualizerGraph *equalizer_graph); | |
38 static void ui_skinned_equalizer_graph_destroy (GtkObject *object); | |
39 static void ui_skinned_equalizer_graph_realize (GtkWidget *widget); | |
40 static void ui_skinned_equalizer_graph_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
41 static void ui_skinned_equalizer_graph_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
42 static gboolean ui_skinned_equalizer_graph_expose (GtkWidget *widget, GdkEventExpose *event); | |
43 static void ui_skinned_equalizer_graph_toggle_scaled (UiSkinnedEqualizerGraph *equalizer_graph); | |
44 | |
45 static GtkWidgetClass *parent_class = NULL; | |
46 static guint equalizer_graph_signals[LAST_SIGNAL] = { 0 }; | |
47 | |
48 GType ui_skinned_equalizer_graph_get_type() { | |
49 static GType equalizer_graph_type = 0; | |
50 if (!equalizer_graph_type) { | |
51 static const GTypeInfo equalizer_graph_info = { | |
52 sizeof (UiSkinnedEqualizerGraphClass), | |
53 NULL, | |
54 NULL, | |
55 (GClassInitFunc) ui_skinned_equalizer_graph_class_init, | |
56 NULL, | |
57 NULL, | |
58 sizeof (UiSkinnedEqualizerGraph), | |
59 0, | |
60 (GInstanceInitFunc) ui_skinned_equalizer_graph_init, | |
61 }; | |
62 equalizer_graph_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedEqualizerGraph", &equalizer_graph_info, 0); | |
63 } | |
64 | |
65 return equalizer_graph_type; | |
66 } | |
67 | |
68 static void ui_skinned_equalizer_graph_class_init(UiSkinnedEqualizerGraphClass *klass) { | |
69 GObjectClass *gobject_class; | |
70 GtkObjectClass *object_class; | |
71 GtkWidgetClass *widget_class; | |
72 | |
73 gobject_class = G_OBJECT_CLASS(klass); | |
74 object_class = (GtkObjectClass*) klass; | |
75 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
3017
diff
changeset
|
76 parent_class = g_type_class_peek_parent(klass); |
2591 | 77 |
78 object_class->destroy = ui_skinned_equalizer_graph_destroy; | |
79 | |
80 widget_class->realize = ui_skinned_equalizer_graph_realize; | |
81 widget_class->expose_event = ui_skinned_equalizer_graph_expose; | |
82 widget_class->size_request = ui_skinned_equalizer_graph_size_request; | |
83 widget_class->size_allocate = ui_skinned_equalizer_graph_size_allocate; | |
84 | |
85 klass->scaled = ui_skinned_equalizer_graph_toggle_scaled; | |
86 | |
87 equalizer_graph_signals[DOUBLED] = | |
88 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
89 G_STRUCT_OFFSET (UiSkinnedEqualizerGraphClass, scaled), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2971
diff
changeset
|
90 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2591 | 91 } |
92 | |
93 static void ui_skinned_equalizer_graph_init(UiSkinnedEqualizerGraph *equalizer_graph) { | |
94 equalizer_graph->width = 113; | |
95 equalizer_graph->height = 19; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
96 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
97 GTK_WIDGET_SET_FLAGS(equalizer_graph, GTK_NO_WINDOW); |
2591 | 98 } |
99 | |
100 GtkWidget* ui_skinned_equalizer_graph_new(GtkWidget *fixed, gint x, gint y) { | |
101 UiSkinnedEqualizerGraph *equalizer_graph = g_object_new (ui_skinned_equalizer_graph_get_type (), NULL); | |
102 | |
103 equalizer_graph->x = x; | |
104 equalizer_graph->y = y; | |
105 equalizer_graph->skin_index = SKIN_EQMAIN; | |
106 equalizer_graph->scaled = FALSE; | |
107 | |
108 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(equalizer_graph), equalizer_graph->x, equalizer_graph->y); | |
109 | |
110 return GTK_WIDGET(equalizer_graph); | |
111 } | |
112 | |
113 static void ui_skinned_equalizer_graph_destroy(GtkObject *object) { | |
114 UiSkinnedEqualizerGraph *equalizer_graph; | |
115 | |
116 g_return_if_fail (object != NULL); | |
117 g_return_if_fail (UI_SKINNED_IS_EQUALIZER_GRAPH (object)); | |
118 | |
119 equalizer_graph = UI_SKINNED_EQUALIZER_GRAPH (object); | |
120 | |
121 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
122 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
123 } | |
124 | |
125 static void ui_skinned_equalizer_graph_realize(GtkWidget *widget) { | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
126 if (GTK_WIDGET_CLASS (parent_class)->realize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
127 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); |
2591 | 128 } |
129 | |
130 static void ui_skinned_equalizer_graph_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
131 UiSkinnedEqualizerGraph *equalizer_graph = UI_SKINNED_EQUALIZER_GRAPH(widget); | |
132 | |
133 requisition->width = equalizer_graph->width*(equalizer_graph->scaled ? config.scale_factor : 1); | |
134 requisition->height = equalizer_graph->height*(equalizer_graph->scaled ? config.scale_factor : 1); | |
135 } | |
136 | |
137 static void ui_skinned_equalizer_graph_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
138 UiSkinnedEqualizerGraph *equalizer_graph = UI_SKINNED_EQUALIZER_GRAPH (widget); | |
139 | |
140 widget->allocation = *allocation; | |
141 widget->allocation.x *= (equalizer_graph->scaled ? config.scale_factor : 1); | |
142 widget->allocation.y *= (equalizer_graph->scaled ? config.scale_factor : 1); | |
143 | |
144 equalizer_graph->x = widget->allocation.x/(equalizer_graph->scaled ? config.scale_factor : 1); | |
145 equalizer_graph->y = widget->allocation.y/(equalizer_graph->scaled ? config.scale_factor : 1); | |
146 } | |
147 | |
148 void | |
149 init_spline(gfloat * x, gfloat * y, gint n, gfloat * y2) | |
150 { | |
151 gint i, k; | |
152 gfloat p, qn, sig, un, *u; | |
153 | |
154 u = (gfloat *) g_malloc(n * sizeof(gfloat)); | |
155 | |
156 y2[0] = u[0] = 0.0; | |
157 | |
158 for (i = 1; i < n - 1; i++) { | |
159 sig = ((gfloat) x[i] - x[i - 1]) / ((gfloat) x[i + 1] - x[i - 1]); | |
160 p = sig * y2[i - 1] + 2.0; | |
161 y2[i] = (sig - 1.0) / p; | |
162 u[i] = | |
163 (((gfloat) y[i + 1] - y[i]) / (x[i + 1] - x[i])) - | |
164 (((gfloat) y[i] - y[i - 1]) / (x[i] - x[i - 1])); | |
165 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p; | |
166 } | |
167 qn = un = 0.0; | |
168 | |
169 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0); | |
170 for (k = n - 2; k >= 0; k--) | |
171 y2[k] = y2[k] * y2[k + 1] + u[k]; | |
172 g_free(u); | |
173 } | |
174 | |
175 gfloat | |
176 eval_spline(gfloat xa[], gfloat ya[], gfloat y2a[], gint n, gfloat x) | |
177 { | |
178 gint klo, khi, k; | |
179 gfloat h, b, a; | |
180 | |
181 klo = 0; | |
182 khi = n - 1; | |
183 while (khi - klo > 1) { | |
184 k = (khi + klo) >> 1; | |
185 if (xa[k] > x) | |
186 khi = k; | |
187 else | |
188 klo = k; | |
189 } | |
190 h = xa[khi] - xa[klo]; | |
191 a = (xa[khi] - x) / h; | |
192 b = (x - xa[klo]) / h; | |
193 return (a * ya[klo] + b * ya[khi] + | |
194 ((a * a * a - a) * y2a[klo] + | |
195 (b * b * b - b) * y2a[khi]) * (h * h) / 6.0); | |
196 } | |
197 | |
198 static gboolean ui_skinned_equalizer_graph_expose(GtkWidget *widget, GdkEventExpose *event) { | |
199 g_return_val_if_fail (widget != NULL, FALSE); | |
200 g_return_val_if_fail (UI_SKINNED_IS_EQUALIZER_GRAPH (widget), FALSE); | |
201 g_return_val_if_fail (event != NULL, FALSE); | |
202 | |
203 UiSkinnedEqualizerGraph *equalizer_graph = UI_SKINNED_EQUALIZER_GRAPH (widget); | |
204 g_return_val_if_fail (equalizer_graph->width > 0 && equalizer_graph->height > 0, FALSE); | |
205 | |
206 GdkPixbuf *obj = NULL; | |
207 | |
208 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, equalizer_graph->width, equalizer_graph->height); | |
209 | |
210 guint32 cols[19], rowstride; | |
211 gint i, y, ymin, ymax, py = 0; | |
212 gfloat x[] = { 0, 11, 23, 35, 47, 59, 71, 83, 97, 109 }, yf[10]; | |
213 guchar* pixels, *p; | |
214 gint n_channels; | |
215 /* | |
216 * This avoids the init_spline() function to be inlined. | |
217 * Inlining the function caused troubles when compiling with | |
218 * `-O' (at least on FreeBSD). | |
219 */ | |
220 void (*__init_spline) (gfloat *, gfloat *, gint, gfloat *) = init_spline; | |
221 | |
222 skin_draw_pixbuf(widget, aud_active_skin, obj, equalizer_graph->skin_index, 0, 294, 0, 0, | |
223 equalizer_graph->width, equalizer_graph->height); | |
224 skin_draw_pixbuf(widget, aud_active_skin, obj, equalizer_graph->skin_index, 0, 314, | |
225 0, 9 + ((aud_cfg->equalizer_preamp * 9) / 20), | |
226 equalizer_graph->width, 1); | |
227 | |
228 skin_get_eq_spline_colors(aud_active_skin, cols); | |
229 | |
230 __init_spline(x, aud_cfg->equalizer_bands, 10, yf); | |
231 for (i = 0; i < 109; i++) { | |
232 y = 9 - | |
233 (gint) ((eval_spline(x, aud_cfg->equalizer_bands, yf, 10, i) * | |
234 9.0) / EQUALIZER_MAX_GAIN); | |
235 if (y < 0) | |
236 y = 0; | |
237 if (y > 18) | |
238 y = 18; | |
239 if (!i) | |
240 py = y; | |
241 if (y < py) { | |
242 ymin = y; | |
243 ymax = py; | |
244 } | |
245 else { | |
246 ymin = py; | |
247 ymax = y; | |
248 } | |
249 py = y; | |
250 | |
251 pixels = gdk_pixbuf_get_pixels(obj); | |
252 rowstride = gdk_pixbuf_get_rowstride(obj); | |
253 n_channels = gdk_pixbuf_get_n_channels(obj); | |
254 | |
255 for (y = ymin; y <= ymax; y++) | |
256 { | |
257 p = pixels + (y * rowstride) + (( i + 2) * n_channels); | |
258 p[0] = (cols[y] & 0xff0000) >> 16; | |
259 p[1] = (cols[y] & 0x00ff00) >> 8; | |
260 p[2] = (cols[y] & 0x0000ff); | |
261 /* do we really need to treat the alpha channel? */ | |
262 /*if (n_channels == 4) | |
263 p[3] = cols[y] >> 24;*/ | |
264 } | |
265 } | |
266 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
267 ui_skinned_widget_draw_with_coordinates(widget, obj, equalizer_graph->width, equalizer_graph->height, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
268 widget->allocation.x, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
269 widget->allocation.y, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2591
diff
changeset
|
270 equalizer_graph->scaled); |
2591 | 271 |
272 g_object_unref(obj); | |
273 | |
274 return FALSE; | |
275 } | |
276 | |
277 static void ui_skinned_equalizer_graph_toggle_scaled(UiSkinnedEqualizerGraph *equalizer_graph) { | |
278 GtkWidget *widget = GTK_WIDGET (equalizer_graph); | |
279 | |
280 equalizer_graph->scaled = !equalizer_graph->scaled; | |
281 gtk_widget_set_size_request(widget, equalizer_graph->width*(equalizer_graph->scaled ? config.scale_factor : 1), | |
282 equalizer_graph->height*(equalizer_graph->scaled ? config.scale_factor : 1)); | |
283 | |
284 gtk_widget_queue_draw(GTK_WIDGET(equalizer_graph)); | |
285 } |