annotate audacious/widgets/eq_graph.c @ 2085:472be23d11a1 trunk

[svn] - finish conversion to new API.
author nenolod
date Mon, 11 Dec 2006 04:19:56 -0800
parents a6e6d3500c13
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
3 *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
4 * Based on XMMS:
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
6 *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
10 * (at your option) any later version.
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
11 *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
16 *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
20 */
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
21
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
22 #include "widgetcore.h"
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
23
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
24 #include <glib.h>
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
25
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
26 #include "main.h"
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
27 #include "skin.h"
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
28
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
29 void
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
30 init_spline(gfloat * x, gfloat * y, gint n, gfloat * y2)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
31 {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
32 gint i, k;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
33 gfloat p, qn, sig, un, *u;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
34
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
35 u = (gfloat *) g_malloc(n * sizeof(gfloat));
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
36
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
37 y2[0] = u[0] = 0.0;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
38
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
39 for (i = 1; i < n - 1; i++) {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
40 sig = ((gfloat) x[i] - x[i - 1]) / ((gfloat) x[i + 1] - x[i - 1]);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
41 p = sig * y2[i - 1] + 2.0;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
42 y2[i] = (sig - 1.0) / p;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
43 u[i] =
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
44 (((gfloat) y[i + 1] - y[i]) / (x[i + 1] - x[i])) -
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
45 (((gfloat) y[i] - y[i - 1]) / (x[i] - x[i - 1]));
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
46 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
47 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
48 qn = un = 0.0;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
49
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
50 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
51 for (k = n - 2; k >= 0; k--)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
52 y2[k] = y2[k] * y2[k + 1] + u[k];
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
53 g_free(u);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
54 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
55
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
56 gfloat
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
57 eval_spline(gfloat xa[], gfloat ya[], gfloat y2a[], gint n, gfloat x)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
58 {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
59 gint klo, khi, k;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
60 gfloat h, b, a;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
61
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
62 klo = 0;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
63 khi = n - 1;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
64 while (khi - klo > 1) {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
65 k = (khi + klo) >> 1;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
66 if (xa[k] > x)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
67 khi = k;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
68 else
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
69 klo = k;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
70 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
71 h = xa[khi] - xa[klo];
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
72 a = (xa[khi] - x) / h;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
73 b = (x - xa[klo]) / h;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
74 return (a * ya[klo] + b * ya[khi] +
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
75 ((a * a * a - a) * y2a[klo] +
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
76 (b * b * b - b) * y2a[khi]) * (h * h) / 6.0);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
77 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
78
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
79 void
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
80 eqgraph_draw(Widget * w)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
81 {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
82 EqGraph *eg = (EqGraph *) w;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
83 GdkPixmap *obj;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
84 GdkColor col;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
85 guint32 cols[19];
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
86 gint i, y, ymin, ymax, py = 0;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
87 gfloat x[] = { 0, 11, 23, 35, 47, 59, 71, 83, 97, 109 }, yf[10];
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
88
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
89 /*
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
90 * This avoids the init_spline() function to be inlined.
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
91 * Inlining the function caused troubles when compiling with
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
92 * `-O' (at least on FreeBSD).
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
93 */
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
94 void (*__init_spline) (gfloat *, gfloat *, gint, gfloat *) = init_spline;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
95
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
96 obj = eg->eg_widget.parent;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
97 skin_draw_pixmap(bmp_active_skin, obj, eg->eg_widget.gc, SKIN_EQMAIN,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
98 0, 294, eg->eg_widget.x, eg->eg_widget.y,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
99 eg->eg_widget.width, eg->eg_widget.height);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
100 skin_draw_pixmap(bmp_active_skin, obj, eg->eg_widget.gc, SKIN_EQMAIN,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
101 0, 314, eg->eg_widget.x,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
102 eg->eg_widget.y + 9 +
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
103 ((cfg.equalizer_preamp * 9) / 20),
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
104 eg->eg_widget.width, 1);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
105
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
106 skin_get_eq_spline_colors(bmp_active_skin, cols);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
107
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
108 __init_spline(x, cfg.equalizer_bands, 10, yf);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
109 for (i = 0; i < 109; i++) {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
110 y = 9 -
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
111 (gint) ((eval_spline(x, cfg.equalizer_bands, yf, 10, i) *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
112 9.0) / 20.0);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
113 if (y < 0)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
114 y = 0;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
115 if (y > 18)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
116 y = 18;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
117 if (!i)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
118 py = y;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
119 if (y < py) {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
120 ymin = y;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
121 ymax = py;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
122 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
123 else {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
124 ymin = py;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
125 ymax = y;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
126 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
127 py = y;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
128 for (y = ymin; y <= ymax; y++) {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
129 col.pixel = cols[y];
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
130 gdk_gc_set_foreground(eg->eg_widget.gc, &col);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
131 gdk_draw_point(obj, eg->eg_widget.gc, eg->eg_widget.x + i + 2,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
132 eg->eg_widget.y + y);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
133 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
134 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
135 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
136
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
137 EqGraph *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
138 create_eqgraph(GList ** wlist, GdkPixmap * parent, GdkGC * gc, gint x, gint y)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
139 {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
140 EqGraph *eg;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
141
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
142 eg = g_new0(EqGraph, 1);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
143 widget_init(&eg->eg_widget, parent, gc, x, y, 113, 19, TRUE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
144 eg->eg_widget.draw = eqgraph_draw;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
145
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
146 widget_list_add(wlist, WIDGET(eg));
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
147
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
148 return eg;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents:
diff changeset
149 }