Mercurial > audlegacy
annotate audacious/equalizer.c @ 1463:47c7695095d4 trunk
[svn] - ok, lets use real URIs here
author | nenolod |
---|---|
date | Wed, 02 Aug 2006 17:52:07 -0700 |
parents | 705d4c089fce |
children | 06329cbf186a |
rev | line source |
---|---|
1068 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2006 Audacious development team. | |
3 * | |
4 * BMP - Cross-platform multimedia player | |
0 | 5 * Copyright (C) 2003-2004 BMP development team. |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
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 | |
1459 | 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 23 */ |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 # include "config.h" | |
27 #endif | |
28 | |
29 #include "equalizer.h" | |
30 | |
31 #include <glib.h> | |
32 #include <glib/gi18n.h> | |
33 #include <gtk/gtk.h> | |
34 #include <gdk/gdk.h> | |
35 #include <gdk/gdkkeysyms.h> | |
36 #include <stdio.h> | |
37 #include <math.h> | |
38 #include <string.h> | |
39 | |
40 #include <gdk/gdkx.h> | |
41 #include <X11/Xlib.h> | |
42 | |
1064 | 43 #include "dock.h" |
0 | 44 #include "eq_graph.h" |
45 #include "eq_slider.h" | |
46 #include "hints.h" | |
47 #include "hslider.h" | |
48 #include "input.h" | |
49 #include "main.h" | |
50 #include "pbutton.h" | |
51 #include "playlist.h" | |
383 | 52 #include "ui_playlist.h" |
0 | 53 #include "skin.h" |
54 #include "tbutton.h" | |
55 #include "util.h" | |
56 #include "output.h" | |
57 | |
58 #include "libaudacious/rcfile.h" | |
59 #include "libaudacious/vfs.h" | |
60 | |
120 | 61 #include "images/audacious_eq.xpm" |
0 | 62 |
63 enum PresetViewCols { | |
64 PRESET_VIEW_COL_NAME, | |
65 PRESET_VIEW_N_COLS | |
66 }; | |
67 | |
68 enum { | |
69 EQUALIZER_PRESETS_LOAD_PRESET, | |
70 EQUALIZER_PRESETS_LOAD_AUTOPRESET, | |
71 EQUALIZER_PRESETS_LOAD_DEFAULT, | |
72 EQUALIZER_PRESETS_LOAD_ZERO, | |
73 EQUALIZER_PRESETS_LOAD_FROM_FILE, | |
74 EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE, | |
75 EQUALIZER_PRESETS_IMPORT_WINAMPFILE, | |
76 EQUALIZER_PRESETS_SAVE_PRESET, | |
77 EQUALIZER_PRESETS_SAVE_AUTOPRESET, | |
78 EQUALIZER_PRESETS_SAVE_DEFAULT, | |
79 EQUALIZER_PRESETS_SAVE_TO_FILE, | |
80 EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE, | |
81 EQUALIZER_PRESETS_DELETE_PRESET, | |
82 EQUALIZER_PRESETS_DELETE_AUTOPRESET | |
83 }; | |
84 | |
85 | |
86 struct _EqualizerPreset { | |
87 gchar *name; | |
88 gfloat preamp, bands[10]; | |
89 }; | |
90 | |
91 typedef struct _EqualizerPreset EqualizerPreset; | |
92 | |
93 | |
94 GtkWidget *equalizerwin; | |
95 | |
96 static GtkWidget *equalizerwin_load_window = NULL; | |
97 static GtkWidget *equalizerwin_load_auto_window = NULL; | |
98 static GtkWidget *equalizerwin_save_window = NULL; | |
99 static GtkWidget *equalizerwin_save_entry; | |
100 static GtkWidget *equalizerwin_save_auto_window = NULL; | |
101 static GtkWidget *equalizerwin_save_auto_entry; | |
102 static GtkWidget *equalizerwin_delete_window = NULL; | |
103 static GtkWidget *equalizerwin_delete_auto_window = NULL; | |
104 | |
105 static GdkPixmap *equalizerwin_bg; | |
106 static GdkGC *equalizerwin_gc; | |
107 | |
108 static GList *equalizerwin_wlist = NULL; | |
109 | |
110 static GtkAccelGroup *equalizerwin_accel; | |
111 | |
112 static TButton *equalizerwin_on, *equalizerwin_auto; | |
113 | |
114 static PButton *equalizerwin_presets, *equalizerwin_shade; | |
115 PButton *equalizerwin_close; | |
116 static EqGraph *equalizerwin_graph; | |
117 static EqSlider *equalizerwin_preamp, *equalizerwin_bands[10]; | |
118 static HSlider *equalizerwin_volume, *equalizerwin_balance; | |
119 | |
120 static GtkItemFactory *equalizerwin_presets_menu; | |
121 | |
122 static GList *equalizer_presets = NULL, *equalizer_auto_presets = NULL; | |
123 | |
124 | |
125 static void equalizerwin_presets_menu_cb(gpointer cb_data, guint action, | |
126 GtkWidget * w); | |
127 | |
128 static GtkItemFactoryEntry equalizerwin_presets_menu_entries[] = { | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
129 {N_("/Load"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 130 {N_("/Load/Preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
131 EQUALIZER_PRESETS_LOAD_PRESET, "<Item>", NULL}, |
0 | 132 {N_("/Load/Auto-load preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
133 EQUALIZER_PRESETS_LOAD_AUTOPRESET, "<Item>", NULL}, |
0 | 134 {N_("/Load/Default"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
135 EQUALIZER_PRESETS_LOAD_DEFAULT, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
136 {"/Load/-", NULL, NULL, 0, "<Separator>", NULL}, |
0 | 137 {N_("/Load/Zero"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
138 EQUALIZER_PRESETS_LOAD_ZERO, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
139 {"/Load/-", NULL, NULL, 0, "<Separator>", NULL}, |
0 | 140 {N_("/Load/From file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
141 EQUALIZER_PRESETS_LOAD_FROM_FILE, "<Item>", NULL}, |
0 | 142 {N_("/Load/From WinAMP EQF file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
143 EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
144 {N_("/Import"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 145 {N_("/Import/WinAMP Presets"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
146 EQUALIZER_PRESETS_IMPORT_WINAMPFILE, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
147 {N_("/Save"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 148 {N_("/Save/Preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
149 EQUALIZER_PRESETS_SAVE_PRESET, "<Item>", NULL}, |
0 | 150 {N_("/Save/Auto-load preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
151 EQUALIZER_PRESETS_SAVE_AUTOPRESET, "<Item>", NULL}, |
0 | 152 {N_("/Save/Default"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
153 EQUALIZER_PRESETS_SAVE_DEFAULT, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
154 {"/Save/-", NULL, NULL, 0, "<Separator>", NULL}, |
0 | 155 {N_("/Save/To file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
156 EQUALIZER_PRESETS_SAVE_TO_FILE, "<Item>", NULL}, |
0 | 157 {N_("/Save/To WinAMP EQF file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
158 EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
159 {N_("/Delete"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 160 {N_("/Delete/Preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
161 EQUALIZER_PRESETS_DELETE_PRESET, "<Item>", NULL}, |
0 | 162 {N_("/Delete/Auto-load preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
163 EQUALIZER_PRESETS_DELETE_AUTOPRESET, "<Item>", NULL}, |
0 | 164 }; |
165 | |
166 static gint equalizerwin_presets_menu_entries_num = | |
167 G_N_ELEMENTS(equalizerwin_presets_menu_entries); | |
168 | |
169 | |
170 EqualizerPreset * | |
171 equalizer_preset_new(const gchar * name) | |
172 { | |
173 EqualizerPreset *preset = g_new0(EqualizerPreset, 1); | |
174 preset->name = g_strdup(name); | |
175 return preset; | |
176 } | |
177 | |
178 void | |
179 equalizer_preset_free(EqualizerPreset * preset) | |
180 { | |
181 if (!preset) | |
182 return; | |
183 | |
184 g_free(preset->name); | |
185 g_free(preset); | |
186 } | |
187 | |
188 | |
189 static void | |
190 equalizerwin_set_shape_mask(void) | |
191 { | |
192 GdkBitmap *mask; | |
193 | |
194 if (cfg.show_wm_decorations) | |
195 return; | |
196 | |
197 mask = skin_get_mask(bmp_active_skin, SKIN_MASK_EQ + cfg.equalizer_shaded); | |
198 gtk_widget_shape_combine_mask(equalizerwin, mask, 0, 0); | |
199 } | |
200 | |
201 | |
202 void | |
203 equalizerwin_set_shade_menu_cb(gboolean shaded) | |
204 { | |
205 cfg.equalizer_shaded = shaded; | |
206 | |
207 equalizerwin_set_shape_mask(); | |
208 | |
209 if (shaded) { | |
1064 | 210 dock_shade(dock_window_list, GTK_WINDOW(equalizerwin), 14); |
0 | 211 pbutton_set_button_data(equalizerwin_shade, -1, 3, -1, 47); |
212 pbutton_set_skin_index1(equalizerwin_shade, SKIN_EQ_EX); | |
213 pbutton_set_button_data(equalizerwin_close, 11, 38, 11, 47); | |
214 pbutton_set_skin_index(equalizerwin_close, SKIN_EQ_EX); | |
215 widget_show(WIDGET(equalizerwin_volume)); | |
216 widget_show(WIDGET(equalizerwin_balance)); | |
217 } | |
218 else { | |
1064 | 219 dock_shade(dock_window_list, GTK_WINDOW(equalizerwin), 116); |
0 | 220 pbutton_set_button_data(equalizerwin_shade, -1, 137, -1, 38); |
221 pbutton_set_skin_index1(equalizerwin_shade, SKIN_EQMAIN); | |
222 pbutton_set_button_data(equalizerwin_close, 0, 116, 0, 125); | |
223 pbutton_set_skin_index(equalizerwin_close, SKIN_EQMAIN); | |
224 widget_hide(WIDGET(equalizerwin_volume)); | |
225 widget_hide(WIDGET(equalizerwin_balance)); | |
226 } | |
227 | |
228 draw_equalizer_window(TRUE); | |
229 } | |
230 | |
231 static void | |
232 equalizerwin_set_shade(gboolean shaded) | |
233 { | |
234 GtkWidget *widget; | |
235 widget = gtk_item_factory_get_widget(mainwin_view_menu, | |
236 "/Roll up Equalizer"); | |
237 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), shaded); | |
238 } | |
239 | |
240 static void | |
241 equalizerwin_shade_toggle(void) | |
242 { | |
243 equalizerwin_set_shade(!cfg.equalizer_shaded); | |
244 } | |
245 | |
246 static void | |
247 equalizerwin_raise(void) | |
248 { | |
249 if (cfg.equalizer_visible) | |
250 gtk_window_present(GTK_WINDOW(equalizerwin)); | |
251 } | |
252 | |
253 void | |
254 equalizerwin_eq_changed(void) | |
255 { | |
256 gint i; | |
257 | |
258 cfg.equalizer_preamp = eqslider_get_position(equalizerwin_preamp); | |
259 for (i = 0; i < 10; i++) | |
260 cfg.equalizer_bands[i] = eqslider_get_position(equalizerwin_bands[i]); | |
261 /* um .. i think we need both of these for xmms compatibility .. | |
262 not sure. -larne */ | |
263 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
264 cfg.equalizer_bands); | |
265 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
266 cfg.equalizer_bands); | |
267 | |
268 widget_draw(WIDGET(equalizerwin_graph)); | |
269 } | |
270 | |
271 static void | |
272 equalizerwin_on_pushed(gboolean toggled) | |
273 { | |
274 cfg.equalizer_active = toggled; | |
275 equalizerwin_eq_changed(); | |
276 } | |
277 | |
278 static void | |
279 equalizerwin_presets_pushed(void) | |
280 { | |
281 GdkModifierType modmask; | |
282 gint x, y; | |
283 | |
284 gdk_window_get_pointer(NULL, &x, &y, &modmask); | |
285 util_item_factory_popup(equalizerwin_presets_menu, x, y, 1, | |
286 GDK_CURRENT_TIME); | |
287 } | |
288 | |
289 static void | |
290 equalizerwin_auto_pushed(gboolean toggled) | |
291 { | |
292 cfg.equalizer_autoload = toggled; | |
293 } | |
294 | |
295 void | |
296 draw_equalizer_window(gboolean force) | |
297 { | |
298 gboolean redraw; | |
299 | |
300 widget_list_lock(equalizerwin_wlist); | |
301 | |
302 if (force) { | |
303 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg, equalizerwin_gc, | |
304 SKIN_EQMAIN, 0, 0, 0, 0, 275, 116); | |
305 if (gtk_window_has_toplevel_focus(GTK_WINDOW(equalizerwin)) || | |
306 !cfg.dim_titlebar) { | |
307 if (!cfg.equalizer_shaded) | |
308 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg, | |
309 equalizerwin_gc, SKIN_EQMAIN, 0, 134, 0, | |
310 0, 275, 14); | |
311 else | |
312 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg, | |
313 equalizerwin_gc, SKIN_EQ_EX, 0, 0, 0, 0, | |
314 275, 14); | |
315 } | |
316 else { | |
317 if (!cfg.equalizer_shaded) | |
318 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg, | |
319 equalizerwin_gc, SKIN_EQMAIN, 0, 149, 0, | |
320 0, 275, 14); | |
321 else | |
322 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg, | |
323 equalizerwin_gc, SKIN_EQ_EX, 0, 15, 0, 0, | |
324 275, 14); | |
325 | |
326 } | |
327 } | |
328 | |
329 widget_list_draw(equalizerwin_wlist, &redraw, force); | |
330 | |
331 if (force || redraw) { | |
332 widget_list_clear_redraw(equalizerwin_wlist); | |
333 gdk_window_clear(equalizerwin->window); | |
334 gdk_flush(); | |
335 } | |
336 | |
337 widget_list_unlock(equalizerwin_wlist); | |
338 } | |
339 | |
340 static gboolean | |
341 inside_sensitive_widgets(gint x, gint y) | |
342 { | |
343 return (widget_contains(WIDGET(equalizerwin_on), x, y) || | |
344 widget_contains(WIDGET(equalizerwin_auto), x, y) || | |
345 widget_contains(WIDGET(equalizerwin_presets), x, y) || | |
346 widget_contains(WIDGET(equalizerwin_close), x, y) || | |
347 widget_contains(WIDGET(equalizerwin_shade), x, y) || | |
348 widget_contains(WIDGET(equalizerwin_preamp), x, y) || | |
349 widget_contains(WIDGET(equalizerwin_bands[0]), x, y) || | |
350 widget_contains(WIDGET(equalizerwin_bands[1]), x, y) || | |
351 widget_contains(WIDGET(equalizerwin_bands[2]), x, y) || | |
352 widget_contains(WIDGET(equalizerwin_bands[3]), x, y) || | |
353 widget_contains(WIDGET(equalizerwin_bands[4]), x, y) || | |
354 widget_contains(WIDGET(equalizerwin_bands[5]), x, y) || | |
355 widget_contains(WIDGET(equalizerwin_bands[6]), x, y) || | |
356 widget_contains(WIDGET(equalizerwin_bands[7]), x, y) || | |
357 widget_contains(WIDGET(equalizerwin_bands[8]), x, y) || | |
358 widget_contains(WIDGET(equalizerwin_bands[9]), x, y) || | |
359 widget_contains(WIDGET(equalizerwin_volume), x, y) || | |
360 widget_contains(WIDGET(equalizerwin_balance), x, y)); | |
361 } | |
362 | |
363 gboolean | |
364 equalizerwin_press(GtkWidget * widget, GdkEventButton * event, | |
365 gpointer callback_data) | |
366 { | |
367 gint mx, my; | |
368 gboolean grab = TRUE; | |
369 | |
370 mx = event->x; | |
371 my = event->y; | |
372 | |
373 if (event->button == 1 && event->type == GDK_BUTTON_PRESS && | |
374 ((cfg.equalizer_shaded || event->y < 14) && | |
375 !inside_sensitive_widgets(event->x, event->y))) { | |
376 if (0 && hint_move_resize_available()) { | |
377 hint_move_resize(equalizerwin, event->x_root, | |
378 event->y_root, TRUE); | |
379 grab = FALSE; | |
380 } | |
381 else { | |
382 equalizerwin_raise(); | |
1064 | 383 dock_move_press(dock_window_list, GTK_WINDOW(equalizerwin), event, |
384 FALSE); | |
0 | 385 } |
386 } | |
387 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS | |
388 && event->y < 14) { | |
389 equalizerwin_set_shade(!cfg.equalizer_shaded); | |
1064 | 390 if (dock_is_moving(GTK_WINDOW(equalizerwin))) |
391 dock_move_release(GTK_WINDOW(equalizerwin)); | |
0 | 392 } |
393 else if (event->button == 3 && | |
394 !(widget_contains(WIDGET(equalizerwin_on), event->x, event->y) || | |
395 widget_contains(WIDGET(equalizerwin_auto), event->x, event->y))) { | |
396 /* | |
397 * Pop up the main menu a few pixels down to avoid | |
398 * anything to be selected initially. | |
399 */ | |
400 util_item_factory_popup(mainwin_general_menu, event->x_root, | |
401 event->y_root + 2, 3, event->time); | |
402 grab = FALSE; | |
403 } | |
404 else { | |
405 handle_press_cb(equalizerwin_wlist, widget, event); | |
406 draw_equalizer_window(FALSE); | |
407 } | |
408 if (grab) | |
409 gdk_pointer_grab(GDK_WINDOW(equalizerwin->window), FALSE, | |
410 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, | |
411 NULL, NULL, GDK_CURRENT_TIME); | |
412 | |
413 return FALSE; | |
414 } | |
415 | |
416 static void | |
417 equalizerwin_scroll(GtkWidget * widget, GdkEventScroll * event, gpointer data) | |
418 { | |
419 handle_scroll_cb(equalizerwin_wlist, widget, event); | |
420 draw_equalizer_window(FALSE); | |
421 } | |
422 | |
423 static gboolean | |
424 equalizerwin_motion(GtkWidget * widget, | |
425 GdkEventMotion * event, gpointer callback_data) | |
426 { | |
533
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
427 GdkEvent *gevent; |
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
428 |
1068 | 429 if (dock_is_moving(GTK_WINDOW(equalizerwin))) |
430 { | |
431 dock_move_motion(GTK_WINDOW(equalizerwin), event); | |
432 } | |
433 else | |
434 { | |
435 handle_motion_cb(equalizerwin_wlist, widget, event); | |
1069 | 436 draw_equalizer_window(FALSE); |
1068 | 437 } |
1042
286156196e16
[svn] - remove X11-incompliant dock.c, dock.h (sorry)
nenolod
parents:
999
diff
changeset
|
438 |
0 | 439 gdk_flush(); |
440 | |
533
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
441 while ((gevent = gdk_event_get()) != NULL) gdk_event_free(gevent); |
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
442 |
0 | 443 return FALSE; |
444 } | |
445 | |
446 static gboolean | |
447 equalizerwin_release(GtkWidget * widget, | |
448 GdkEventButton * event, gpointer callback_data) | |
449 { | |
450 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
451 gdk_flush(); | |
1068 | 452 |
1064 | 453 if (dock_is_moving(GTK_WINDOW(equalizerwin))) { |
454 dock_move_release(GTK_WINDOW(equalizerwin)); | |
455 } | |
456 else { | |
457 handle_release_cb(equalizerwin_wlist, widget, event); | |
458 draw_equalizer_window(FALSE); | |
459 } | |
0 | 460 |
461 return FALSE; | |
462 } | |
463 | |
464 static gboolean | |
465 equalizerwin_focus_in(GtkWidget * widget, | |
466 GdkEvent * event, | |
467 gpointer data) | |
468 { | |
469 equalizerwin_close->pb_allow_draw = TRUE; | |
470 equalizerwin_shade->pb_allow_draw = TRUE; | |
471 draw_equalizer_window(TRUE); | |
472 return TRUE; | |
473 } | |
474 | |
475 static gboolean | |
476 equalizerwin_focus_out(GtkWidget * widget, | |
477 GdkEventButton * event, | |
478 gpointer data) | |
479 { | |
480 equalizerwin_close->pb_allow_draw = FALSE; | |
481 equalizerwin_shade->pb_allow_draw = FALSE; | |
482 draw_equalizer_window(TRUE); | |
483 return TRUE; | |
484 } | |
485 | |
486 static gboolean | |
487 equalizerwin_keypress(GtkWidget * widget, | |
488 GdkEventKey * event, | |
489 gpointer data) | |
490 { | |
491 if (!cfg.equalizer_shaded) { | |
492 gtk_widget_event(mainwin, (GdkEvent *) event); | |
493 return TRUE; | |
494 } | |
495 | |
496 switch (event->keyval) { | |
497 case GDK_Left: | |
498 case GDK_KP_Left: | |
499 mainwin_set_balance_diff(-4); | |
500 break; | |
501 case GDK_Right: | |
502 case GDK_KP_Right: | |
503 mainwin_set_balance_diff(4); | |
504 break; | |
505 default: | |
506 gtk_widget_event(mainwin, (GdkEvent *) event); | |
507 break; | |
508 } | |
509 | |
510 return FALSE; | |
511 } | |
512 | |
513 static gboolean | |
514 equalizerwin_configure(GtkWidget * window, | |
515 GdkEventConfigure * event, | |
516 gpointer data) | |
517 { | |
518 if (!GTK_WIDGET_VISIBLE(window)) | |
519 return FALSE; | |
520 | |
521 cfg.equalizer_x = event->x; | |
522 cfg.equalizer_y = event->y; | |
523 return FALSE; | |
524 } | |
525 | |
526 static void | |
527 equalizerwin_set_back_pixmap(void) | |
528 { | |
529 gdk_window_set_back_pixmap(equalizerwin->window, equalizerwin_bg, 0); | |
530 gdk_window_clear(equalizerwin->window); | |
531 } | |
532 | |
533 static void | |
534 equalizerwin_close_cb(void) | |
535 { | |
536 equalizerwin_show(FALSE); | |
537 } | |
538 | |
539 static gboolean | |
540 equalizerwin_delete(GtkWidget * widget, | |
541 gpointer data) | |
542 { | |
543 equalizerwin_show(FALSE); | |
544 return TRUE; | |
545 } | |
546 | |
547 static GList * | |
548 equalizerwin_read_presets(const gchar * basename) | |
549 { | |
550 gchar *filename, *name; | |
551 RcFile *rcfile; | |
552 GList *list = NULL; | |
553 gint i, p = 0; | |
554 EqualizerPreset *preset; | |
555 | |
556 filename = g_build_filename(bmp_paths[BMP_PATH_USER_DIR], basename, NULL); | |
557 | |
558 if ((rcfile = bmp_rcfile_open(filename)) == NULL) { | |
559 g_free(filename); | |
560 return NULL; | |
561 } | |
562 | |
563 g_free(filename); | |
564 | |
565 for (;;) { | |
566 gchar section[21]; | |
567 | |
568 g_snprintf(section, sizeof(section), "Preset%d", p++); | |
569 if (bmp_rcfile_read_string(rcfile, "Presets", section, &name)) { | |
570 preset = g_new0(EqualizerPreset, 1); | |
571 preset->name = name; | |
572 bmp_rcfile_read_float(rcfile, name, "Preamp", &preset->preamp); | |
573 for (i = 0; i < 10; i++) { | |
574 gchar band[7]; | |
575 g_snprintf(band, sizeof(band), "Band%d", i); | |
576 bmp_rcfile_read_float(rcfile, name, band, &preset->bands[i]); | |
577 } | |
578 list = g_list_prepend(list, preset); | |
579 } | |
580 else | |
581 break; | |
582 } | |
583 list = g_list_reverse(list); | |
584 bmp_rcfile_free(rcfile); | |
585 return list; | |
586 } | |
587 | |
588 gint | |
589 equalizerwin_volume_frame_cb(gint pos) | |
590 { | |
591 if (equalizerwin_volume) { | |
592 if (pos < 32) | |
593 equalizerwin_volume->hs_knob_nx = | |
594 equalizerwin_volume->hs_knob_px = 1; | |
595 else if (pos < 63) | |
596 equalizerwin_volume->hs_knob_nx = | |
597 equalizerwin_volume->hs_knob_px = 4; | |
598 else | |
599 equalizerwin_volume->hs_knob_nx = | |
600 equalizerwin_volume->hs_knob_px = 7; | |
601 } | |
602 return 1; | |
603 } | |
604 | |
605 static void | |
606 equalizerwin_volume_motion_cb(gint pos) | |
607 { | |
608 gint v = (gint) rint(pos * 100 / 94.0); | |
609 mainwin_adjust_volume_motion(v); | |
610 mainwin_set_volume_slider(v); | |
611 } | |
612 | |
613 static void | |
614 equalizerwin_volume_release_cb(gint pos) | |
615 { | |
616 mainwin_adjust_volume_release(); | |
617 } | |
618 | |
619 static gint | |
620 equalizerwin_balance_frame_cb(gint pos) | |
621 { | |
622 if (equalizerwin_balance) { | |
623 if (pos < 13) | |
624 equalizerwin_balance->hs_knob_nx = | |
625 equalizerwin_balance->hs_knob_px = 11; | |
626 else if (pos < 26) | |
627 equalizerwin_balance->hs_knob_nx = | |
628 equalizerwin_balance->hs_knob_px = 14; | |
629 else | |
630 equalizerwin_balance->hs_knob_nx = | |
631 equalizerwin_balance->hs_knob_px = 17; | |
632 } | |
633 | |
634 return 1; | |
635 } | |
636 | |
637 static void | |
638 equalizerwin_balance_motion_cb(gint pos) | |
639 { | |
640 gint b; | |
641 pos = MIN(pos, 38); /* The skin uses a even number of pixels | |
642 for the balance-slider *sigh* */ | |
643 b = (gint) rint((pos - 19) * 100 / 19.0); | |
644 mainwin_adjust_balance_motion(b); | |
645 mainwin_set_balance_slider(b); | |
646 } | |
647 | |
648 static void | |
649 equalizerwin_balance_release_cb(gint pos) | |
650 { | |
651 mainwin_adjust_balance_release(); | |
652 } | |
653 | |
654 void | |
655 equalizerwin_set_balance_slider(gint percent) | |
656 { | |
657 hslider_set_position(equalizerwin_balance, | |
658 (gint) rint((percent * 19 / 100.0) + 19)); | |
659 } | |
660 | |
661 void | |
662 equalizerwin_set_volume_slider(gint percent) | |
663 { | |
664 hslider_set_position(equalizerwin_volume, | |
665 (gint) rint(percent * 94 / 100.0)); | |
666 } | |
667 | |
668 static void | |
669 equalizerwin_create_widgets(void) | |
670 { | |
671 gint i; | |
672 | |
673 equalizerwin_on = | |
674 create_tbutton(&equalizerwin_wlist, equalizerwin_bg, | |
675 equalizerwin_gc, 14, 18, 25, 12, 10, 119, 128, 119, | |
676 69, 119, 187, 119, equalizerwin_on_pushed, | |
677 SKIN_EQMAIN); | |
678 tbutton_set_toggled(equalizerwin_on, cfg.equalizer_active); | |
679 equalizerwin_auto = | |
680 create_tbutton(&equalizerwin_wlist, equalizerwin_bg, | |
681 equalizerwin_gc, 39, 18, 33, 12, 35, 119, 153, 119, | |
682 94, 119, 212, 119, equalizerwin_auto_pushed, | |
683 SKIN_EQMAIN); | |
684 tbutton_set_toggled(equalizerwin_auto, cfg.equalizer_autoload); | |
685 equalizerwin_presets = | |
686 create_pbutton(&equalizerwin_wlist, equalizerwin_bg, | |
687 equalizerwin_gc, 217, 18, 44, 12, 224, 164, 224, | |
688 176, equalizerwin_presets_pushed, SKIN_EQMAIN); | |
689 equalizerwin_close = | |
690 create_pbutton(&equalizerwin_wlist, equalizerwin_bg, | |
691 equalizerwin_gc, 264, 3, 9, 9, 0, 116, 0, 125, | |
692 equalizerwin_close_cb, SKIN_EQMAIN); | |
693 equalizerwin_close->pb_allow_draw = FALSE; | |
694 | |
695 equalizerwin_shade = | |
696 create_pbutton_ex(&equalizerwin_wlist, equalizerwin_bg, | |
697 equalizerwin_gc, 254, 3, 9, 9, 254, 137, 1, 38, | |
424
d7d70779c074
[svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents:
383
diff
changeset
|
698 equalizerwin_shade_toggle, NULL, SKIN_EQMAIN, SKIN_EQ_EX); |
0 | 699 equalizerwin_shade->pb_allow_draw = FALSE; |
700 | |
701 equalizerwin_graph = | |
702 create_eqgraph(&equalizerwin_wlist, equalizerwin_bg, | |
703 equalizerwin_gc, 86, 17); | |
704 equalizerwin_preamp = | |
705 create_eqslider(&equalizerwin_wlist, equalizerwin_bg, | |
706 equalizerwin_gc, 21, 38); | |
707 eqslider_set_position(equalizerwin_preamp, cfg.equalizer_preamp); | |
708 for (i = 0; i < 10; i++) { | |
709 equalizerwin_bands[i] = | |
710 create_eqslider(&equalizerwin_wlist, equalizerwin_bg, | |
711 equalizerwin_gc, 78 + (i * 18), 38); | |
712 eqslider_set_position(equalizerwin_bands[i], cfg.equalizer_bands[i]); | |
713 } | |
714 | |
715 equalizerwin_volume = | |
716 create_hslider(&equalizerwin_wlist, equalizerwin_bg, | |
717 equalizerwin_gc, 61, 4, 97, 8, 1, 30, 1, 30, 3, 7, | |
718 4, 61, 0, 94, equalizerwin_volume_frame_cb, | |
719 equalizerwin_volume_motion_cb, | |
720 equalizerwin_volume_release_cb, SKIN_EQ_EX); | |
721 equalizerwin_balance = | |
722 create_hslider(&equalizerwin_wlist, equalizerwin_bg, | |
723 equalizerwin_gc, 164, 4, 42, 8, 11, 30, 11, 30, 3, | |
724 7, 4, 164, 0, 39, equalizerwin_balance_frame_cb, | |
725 equalizerwin_balance_motion_cb, | |
726 equalizerwin_balance_release_cb, SKIN_EQ_EX); | |
727 | |
728 if (!cfg.equalizer_shaded) { | |
729 widget_hide(WIDGET(equalizerwin_volume)); | |
730 widget_hide(WIDGET(equalizerwin_balance)); | |
731 } | |
732 else { | |
733 pbutton_set_button_data(equalizerwin_shade, -1, 3, -1, 47); | |
734 pbutton_set_skin_index1(equalizerwin_shade, SKIN_EQ_EX); | |
735 pbutton_set_button_data(equalizerwin_close, 11, 38, 11, 47); | |
736 pbutton_set_skin_index(equalizerwin_close, SKIN_EQ_EX); | |
737 } | |
738 } | |
739 | |
740 | |
741 static void | |
742 equalizerwin_create_window(void) | |
743 { | |
744 GdkPixbuf *icon; | |
745 gint width, height; | |
746 | |
747 equalizerwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
187 | 748 gtk_window_set_title(GTK_WINDOW(equalizerwin), _("Audacious Equalizer")); |
999
386cda529c28
[svn] Add wmclass information to the playlist and equalizer. Patch by cha0smaster, closes bug #481.
chainsaw
parents:
781
diff
changeset
|
749 gtk_window_set_wmclass(GTK_WINDOW(equalizerwin), "equalizer", "Audacious"); |
0 | 750 gtk_window_set_role(GTK_WINDOW(equalizerwin), "equalizer"); |
751 | |
752 width = 275; | |
753 height = cfg.equalizer_shaded ? 14 : 116; | |
754 | |
755 gtk_window_set_default_size(GTK_WINDOW(equalizerwin), width, height); | |
756 gtk_window_set_resizable(GTK_WINDOW(equalizerwin), FALSE); | |
1068 | 757 |
758 dock_window_list = dock_window_set_decorated(dock_window_list, | |
759 GTK_WINDOW(equalizerwin), | |
760 cfg.show_wm_decorations); | |
0 | 761 |
1085 | 762 gtk_window_set_transient_for(GTK_WINDOW(equalizerwin), |
763 GTK_WINDOW(mainwin)); | |
764 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(equalizerwin), TRUE); | |
765 | |
0 | 766 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) bmp_eq_icon); |
767 gtk_window_set_icon(GTK_WINDOW(equalizerwin), icon); | |
768 g_object_unref(icon); | |
769 | |
770 gtk_widget_set_app_paintable(equalizerwin, TRUE); | |
771 | |
772 if (cfg.equalizer_x != -1 && cfg.save_window_position) | |
773 gtk_window_move(GTK_WINDOW(equalizerwin), | |
774 cfg.equalizer_x, cfg.equalizer_y); | |
775 | |
776 gtk_widget_set_events(equalizerwin, | |
777 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
778 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
779 GDK_VISIBILITY_NOTIFY_MASK); | |
780 gtk_widget_realize(equalizerwin); | |
781 | |
782 util_set_cursor(equalizerwin); | |
783 | |
784 g_signal_connect(equalizerwin, "delete_event", | |
785 G_CALLBACK(equalizerwin_delete), NULL); | |
786 g_signal_connect(equalizerwin, "button_press_event", | |
787 G_CALLBACK(equalizerwin_press), NULL); | |
788 g_signal_connect(equalizerwin, "button_release_event", | |
789 G_CALLBACK(equalizerwin_release), NULL); | |
790 g_signal_connect(equalizerwin, "motion_notify_event", | |
791 G_CALLBACK(equalizerwin_motion), NULL); | |
792 g_signal_connect_after(equalizerwin, "focus_in_event", | |
793 G_CALLBACK(equalizerwin_focus_in), NULL); | |
794 g_signal_connect_after(equalizerwin, "focus_out_event", | |
795 G_CALLBACK(equalizerwin_focus_out), NULL); | |
796 g_signal_connect(equalizerwin, "configure_event", | |
797 G_CALLBACK(equalizerwin_configure), NULL); | |
798 g_signal_connect(equalizerwin, "style_set", | |
799 G_CALLBACK(equalizerwin_set_back_pixmap), NULL); | |
800 g_signal_connect(equalizerwin, "key_press_event", | |
801 G_CALLBACK(equalizerwin_keypress), NULL); | |
802 g_signal_connect(equalizerwin, "scroll_event", | |
803 G_CALLBACK(equalizerwin_scroll), NULL); | |
804 } | |
805 | |
806 void | |
807 equalizerwin_create_popup_menus(void) | |
808 { | |
809 equalizerwin_accel = gtk_accel_group_new(); | |
810 gtk_window_add_accel_group(GTK_WINDOW(equalizerwin), equalizerwin_accel); | |
811 | |
812 equalizerwin_presets_menu = create_menu(equalizerwin_presets_menu_entries, | |
813 equalizerwin_presets_menu_entries_num, | |
814 NULL); | |
815 } | |
816 | |
817 void | |
818 equalizerwin_create(void) | |
819 { | |
820 equalizer_presets = equalizerwin_read_presets("eq.preset"); | |
821 equalizer_auto_presets = equalizerwin_read_presets("eq.auto_preset"); | |
822 | |
823 equalizerwin_create_window(); | |
824 equalizerwin_create_popup_menus(); | |
825 | |
826 equalizerwin_gc = gdk_gc_new(equalizerwin->window); | |
827 equalizerwin_bg = gdk_pixmap_new(equalizerwin->window, 275, 116, -1); | |
828 | |
829 equalizerwin_create_widgets(); | |
830 | |
831 equalizerwin_set_back_pixmap(); | |
832 gdk_window_set_back_pixmap(equalizerwin->window, equalizerwin_bg, 0); | |
833 } | |
834 | |
835 | |
836 void | |
837 equalizerwin_show(gboolean show) | |
838 { | |
839 GtkWidget *item = gtk_item_factory_get_widget(mainwin_view_menu, | |
840 "/Show Equalizer"); | |
841 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), show); | |
842 } | |
843 | |
844 void | |
845 equalizerwin_real_show(void) | |
846 { | |
847 /* | |
848 * This function should only be called from the | |
849 * main menu signal handler | |
850 */ | |
851 | |
852 gint x, y; | |
853 | |
854 gtk_window_get_position(GTK_WINDOW(equalizerwin), &x, &y); | |
855 gtk_window_move(GTK_WINDOW(equalizerwin), x, y); | |
856 gtk_widget_set_size_request(equalizerwin, 275, | |
857 (cfg.equalizer_shaded ? 14 : 116)); | |
858 gdk_flush(); | |
859 draw_equalizer_window(TRUE); | |
860 cfg.equalizer_visible = TRUE; | |
861 tbutton_set_toggled(mainwin_eq, TRUE); | |
862 | |
863 gtk_widget_show(equalizerwin); | |
864 } | |
865 | |
866 void | |
867 equalizerwin_real_hide(void) | |
868 { | |
869 /* | |
870 * This function should only be called from the | |
871 * main menu signal handler | |
872 */ | |
873 gtk_widget_hide(equalizerwin); | |
874 cfg.equalizer_visible = FALSE; | |
875 tbutton_set_toggled(mainwin_eq, FALSE); | |
876 } | |
877 | |
878 static EqualizerPreset * | |
879 equalizerwin_find_preset(GList * list, const gchar * name) | |
880 { | |
881 GList *node = list; | |
882 EqualizerPreset *preset; | |
883 | |
884 while (node) { | |
885 preset = node->data; | |
886 if (!strcasecmp(preset->name, name)) | |
887 return preset; | |
888 node = g_list_next(node); | |
889 } | |
890 return NULL; | |
891 } | |
892 | |
893 static void | |
894 equalizerwin_write_preset_file(GList * list, const gchar * basename) | |
895 { | |
896 gchar *filename, *tmp; | |
897 gint i, p; | |
898 EqualizerPreset *preset; | |
899 RcFile *rcfile; | |
900 GList *node; | |
901 | |
902 rcfile = bmp_rcfile_new(); | |
903 p = 0; | |
904 for (node = list; node; node = g_list_next(node)) { | |
905 preset = node->data; | |
906 tmp = g_strdup_printf("Preset%d", p++); | |
907 bmp_rcfile_write_string(rcfile, "Presets", tmp, preset->name); | |
908 g_free(tmp); | |
909 bmp_rcfile_write_float(rcfile, preset->name, "Preamp", | |
910 preset->preamp); | |
911 for (i = 0; i < 10; i++) { | |
912 tmp = g_strdup_printf("Band%d\n", i); | |
913 bmp_rcfile_write_float(rcfile, preset->name, tmp, | |
914 preset->bands[i]); | |
915 g_free(tmp); | |
916 } | |
917 } | |
918 | |
919 filename = g_build_filename(bmp_paths[BMP_PATH_USER_DIR], basename, NULL); | |
920 bmp_rcfile_write(rcfile, filename); | |
921 bmp_rcfile_free(rcfile); | |
922 g_free(filename); | |
923 } | |
924 | |
925 static gboolean | |
926 equalizerwin_load_preset(GList * list, const gchar * name) | |
927 { | |
928 EqualizerPreset *preset; | |
929 gint i; | |
930 | |
931 if ((preset = equalizerwin_find_preset(list, name)) != NULL) { | |
932 eqslider_set_position(equalizerwin_preamp, preset->preamp); | |
933 for (i = 0; i < 10; i++) | |
934 eqslider_set_position(equalizerwin_bands[i], preset->bands[i]); | |
935 equalizerwin_eq_changed(); | |
936 return TRUE; | |
937 } | |
938 return FALSE; | |
939 } | |
940 | |
941 static GList * | |
942 equalizerwin_save_preset(GList * list, const gchar * name, | |
943 const gchar * filename) | |
944 { | |
945 gint i; | |
946 EqualizerPreset *preset; | |
947 | |
948 if (!(preset = equalizerwin_find_preset(list, name))) { | |
949 preset = g_new0(EqualizerPreset, 1); | |
950 preset->name = g_strdup(name); | |
951 list = g_list_append(list, preset); | |
952 } | |
953 | |
954 preset->preamp = eqslider_get_position(equalizerwin_preamp); | |
955 for (i = 0; i < 10; i++) | |
956 preset->bands[i] = eqslider_get_position(equalizerwin_bands[i]); | |
957 | |
958 equalizerwin_write_preset_file(list, filename); | |
959 | |
960 return list; | |
961 } | |
962 | |
963 static GList * | |
964 equalizerwin_delete_preset(GList * list, gchar * name, gchar * filename) | |
965 { | |
966 EqualizerPreset *preset; | |
967 GList *node; | |
968 | |
969 if (!(preset = equalizerwin_find_preset(list, name))) | |
970 return list; | |
971 | |
972 if (!(node = g_list_find(list, preset))) | |
973 return list; | |
974 | |
975 list = g_list_remove_link(list, node); | |
976 equalizer_preset_free(preset); | |
977 g_list_free_1(node); | |
978 | |
979 equalizerwin_write_preset_file(list, filename); | |
980 | |
981 return list; | |
982 } | |
983 | |
984 | |
985 static GList * | |
986 import_winamp_eqf(VFSFile * file) | |
987 { | |
988 gchar header[31]; | |
989 gchar name[257]; | |
990 gchar bands[11]; | |
991 gint i = 0; | |
992 GList *list = NULL; | |
993 EqualizerPreset *preset; | |
994 | |
995 vfs_fread(header, 1, 31, file); | |
996 if (!strncmp(header, "Winamp EQ library file v1.1", 27)) { | |
997 while (vfs_fread(name, 1, 257, file)) { | |
998 preset = equalizer_preset_new(name); | |
999 preset->preamp = 20.0 - ((bands[10] * 40.0) / 64); | |
1000 | |
1001 vfs_fread(bands, 1, 11, file); | |
1002 | |
1003 for (i = 0; i < 10; i++) | |
1004 preset->bands[i] = 20.0 - ((bands[i] * 40.0) / 64); | |
1005 | |
1006 list = g_list_prepend(list, preset); | |
1007 } | |
1008 } | |
1009 | |
1010 list = g_list_reverse(list); | |
1011 return list; | |
1012 } | |
1013 | |
1014 static void | |
1015 equalizerwin_read_winamp_eqf(VFSFile * file) | |
1016 { | |
1017 gchar header[31]; | |
1018 guchar bands[11]; | |
1019 gint i; | |
1020 | |
1021 vfs_fread(header, 1, 31, file); | |
1022 | |
1023 if (!strncmp(header, "Winamp EQ library file v1.1", 27)) { | |
1024 /* Skip name */ | |
1025 if (vfs_fseek(file, 257, SEEK_CUR) == -1) | |
1026 return; | |
1027 | |
1028 if (vfs_fread(bands, 1, 11, file) != 11) | |
1029 return; | |
1030 | |
1031 eqslider_set_position(equalizerwin_preamp, | |
1032 20.0 - ((bands[10] * 40.0) / 63.0)); | |
1033 | |
1034 for (i = 0; i < 10; i++) | |
1035 eqslider_set_position(equalizerwin_bands[i], | |
1036 20.0 - ((bands[i] * 40.0) / 64.0)); | |
1037 } | |
1038 | |
1039 equalizerwin_eq_changed(); | |
1040 } | |
1041 | |
1042 static void | |
1043 equalizerwin_read_bmp_preset(RcFile * rcfile) | |
1044 { | |
1045 gfloat val; | |
1046 gint i; | |
1047 | |
1048 if (bmp_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val)) | |
1049 eqslider_set_position(equalizerwin_preamp, val); | |
1050 for (i = 0; i < 10; i++) { | |
1051 gchar tmp[7]; | |
1052 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1053 if (bmp_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val)) | |
1054 eqslider_set_position(equalizerwin_bands[i], val); | |
1055 } | |
1056 equalizerwin_eq_changed(); | |
1057 } | |
1058 | |
1059 static void | |
1060 equalizerwin_save_ok(GtkWidget * widget, gpointer data) | |
1061 { | |
1062 const gchar *text; | |
1063 | |
1064 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_entry)); | |
1065 if (strlen(text) != 0) | |
1066 equalizer_presets = | |
1067 equalizerwin_save_preset(equalizer_presets, text, "eq.preset"); | |
1068 gtk_widget_destroy(equalizerwin_save_window); | |
1069 } | |
1070 | |
1071 static void | |
1072 equalizerwin_save_select(GtkCList * clist, gint row, | |
1073 gint column, GdkEventButton * event, gpointer data) | |
1074 { | |
1075 gchar *text; | |
1076 | |
1077 gtk_clist_get_text(clist, row, 0, &text); | |
1078 | |
1079 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_entry), text); | |
1080 if (event->type == GDK_2BUTTON_PRESS) | |
1081 equalizerwin_save_ok(NULL, NULL); | |
1082 | |
1083 } | |
1084 | |
1085 static void | |
1086 equalizerwin_load_ok(GtkWidget * widget, gpointer data) | |
1087 { | |
1088 gchar *text; | |
1089 GtkCList *clist = GTK_CLIST(data); | |
1090 | |
1091 if (clist && clist->selection) { | |
1092 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), | |
1093 0, &text); | |
1094 equalizerwin_load_preset(equalizer_presets, text); | |
1095 } | |
1096 gtk_widget_destroy(equalizerwin_load_window); | |
1097 } | |
1098 | |
1099 static void | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1100 equalizerwin_load_apply(GtkWidget * widget, gpointer data) |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1101 { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1102 gchar *text; |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1103 GtkCList *clist = GTK_CLIST(data); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1104 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1105 if (clist && clist->selection) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1106 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1107 0, &text); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1108 equalizerwin_load_preset(equalizer_presets, text); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1109 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1110 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1111 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1112 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1113 static void |
0 | 1114 equalizerwin_load_select(GtkCList * widget, gint row, |
1115 gint column, GdkEventButton * event, gpointer data) | |
1116 { | |
1117 if (event->type == GDK_2BUTTON_PRESS) | |
1118 equalizerwin_load_ok(NULL, widget); | |
1119 } | |
1120 | |
1121 static void | |
1122 equalizerwin_delete_delete(GtkWidget * widget, gpointer data) | |
1123 { | |
1124 gchar *text; | |
1125 GList *list, *next; | |
1126 GtkCList *clist = GTK_CLIST(data); | |
1127 | |
1128 g_return_if_fail(clist != NULL); | |
1129 | |
1130 list = clist->selection; | |
1131 gtk_clist_freeze(clist); | |
1132 while (list) { | |
1133 next = g_list_next(list); | |
1134 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text); | |
1135 equalizer_auto_presets = | |
1136 equalizerwin_delete_preset(equalizer_presets, text, "eq.preset"); | |
1137 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data)); | |
1138 list = next; | |
1139 } | |
1140 gtk_clist_thaw(clist); | |
1141 } | |
1142 | |
1143 static void | |
1144 equalizerwin_save_auto_ok(GtkWidget * widget, gpointer data) | |
1145 { | |
1146 const gchar *text; | |
1147 | |
1148 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_auto_entry)); | |
1149 if (strlen(text) != 0) | |
1150 equalizer_auto_presets = | |
1151 equalizerwin_save_preset(equalizer_auto_presets, text, | |
1152 "eq.auto_preset"); | |
1153 gtk_widget_destroy(equalizerwin_save_auto_window); | |
1154 } | |
1155 | |
1156 static void | |
1157 equalizerwin_save_auto_select(GtkCList * clist, gint row, | |
1158 gint column, | |
1159 GdkEventButton * event, gpointer data) | |
1160 { | |
1161 gchar *text; | |
1162 | |
1163 gtk_clist_get_text(clist, row, 0, &text); | |
1164 | |
1165 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), text); | |
1166 if (event->type == GDK_2BUTTON_PRESS) | |
1167 equalizerwin_save_auto_ok(NULL, NULL); | |
1168 | |
1169 } | |
1170 | |
1171 static void | |
1172 equalizerwin_load_auto_ok(GtkWidget * widget, gpointer data) | |
1173 { | |
1174 gchar *text; | |
1175 GtkCList *clist = GTK_CLIST(data); | |
1176 | |
1177 if (clist && clist->selection) { | |
1178 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), | |
1179 0, &text); | |
1180 equalizerwin_load_preset(equalizer_auto_presets, text); | |
1181 } | |
1182 gtk_widget_destroy(equalizerwin_load_auto_window); | |
1183 } | |
1184 | |
1185 static void | |
1186 equalizerwin_load_auto_select(GtkWidget * widget, gint row, | |
1187 gint column, | |
1188 GdkEventButton * event, gpointer data) | |
1189 { | |
1190 if (event->type == GDK_2BUTTON_PRESS) | |
1191 equalizerwin_load_auto_ok(NULL, widget); | |
1192 } | |
1193 | |
1194 static void | |
1195 equalizerwin_delete_auto_delete(GtkWidget * widget, gpointer data) | |
1196 { | |
1197 gchar *text; | |
1198 GList *list, *next; | |
1199 GtkCList *clist = GTK_CLIST(data); | |
1200 | |
1201 g_return_if_fail(clist != NULL); | |
1202 | |
1203 list = clist->selection; | |
1204 gtk_clist_freeze(clist); | |
1205 while (list) { | |
1206 next = g_list_next(list); | |
1207 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text); | |
1208 equalizer_auto_presets = | |
1209 equalizerwin_delete_preset(equalizer_auto_presets, text, | |
1210 "eq.auto_preset"); | |
1211 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data)); | |
1212 list = next; | |
1213 } | |
1214 gtk_clist_thaw(clist); | |
1215 } | |
1216 | |
1217 | |
1218 typedef void (*ResponseHandler)(const gchar *filename); | |
1219 | |
1220 static void | |
1221 equalizerwin_file_chooser_on_response(GtkWidget * dialog, | |
1222 gint response, | |
1223 gpointer data) | |
1224 { | |
1225 GtkFileChooser *file_chooser = GTK_FILE_CHOOSER(dialog); | |
1226 ResponseHandler handler = (ResponseHandler) data; | |
1227 gchar *filename; | |
1228 | |
1229 gtk_widget_hide(dialog); | |
1230 | |
1231 switch (response) | |
1232 { | |
1233 case GTK_RESPONSE_ACCEPT: | |
1234 filename = gtk_file_chooser_get_filename(file_chooser); | |
1235 handler(filename); | |
1236 g_free(filename); | |
1237 break; | |
1238 | |
1239 case GTK_RESPONSE_REJECT: | |
1240 break; | |
1241 } | |
1242 | |
1243 gtk_widget_destroy(dialog); | |
1244 } | |
1245 | |
1246 | |
1247 | |
1248 static void | |
1249 load_preset_file(const gchar *filename) | |
1250 { | |
1251 RcFile *rcfile; | |
1252 | |
1253 if ((rcfile = bmp_rcfile_open(filename)) != NULL) { | |
1254 equalizerwin_read_bmp_preset(rcfile); | |
1255 bmp_rcfile_free(rcfile); | |
1256 } | |
1257 } | |
1258 | |
1259 static void | |
1260 load_winamp_file(const gchar * filename) | |
1261 { | |
1262 VFSFile *file; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1263 gchar *tmp; |
0 | 1264 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1265 if (!(file = vfs_fopen(filename, "rb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1266 tmp = g_strconcat("Failed to load WinAmp file: ",filename,"\n",NULL); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1267 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1268 g_free(tmp); |
0 | 1269 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1270 } |
0 | 1271 |
1272 equalizerwin_read_winamp_eqf(file); | |
1273 vfs_fclose(file); | |
1274 } | |
1275 | |
1276 static void | |
1277 import_winamp_file(const gchar * filename) | |
1278 { | |
1279 VFSFile *file; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1280 gchar *tmp; |
0 | 1281 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1282 if (!(file = vfs_fopen(filename, "rb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1283 tmp = g_strconcat("Failed to import WinAmp file: ",filename,"\n",NULL); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1284 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1285 g_free(tmp); |
0 | 1286 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1287 } |
0 | 1288 |
1289 equalizer_presets = g_list_concat(equalizer_presets, | |
1290 import_winamp_eqf(file)); | |
1291 equalizerwin_write_preset_file(equalizer_presets, "eq.preset"); | |
1292 | |
1293 vfs_fclose(file); | |
1294 } | |
1295 | |
1296 static void | |
1297 save_preset_file(const gchar * filename) | |
1298 { | |
1299 RcFile *rcfile; | |
1300 gint i; | |
1301 | |
1302 rcfile = bmp_rcfile_new(); | |
1303 bmp_rcfile_write_float(rcfile, "Equalizer preset", "Preamp", | |
1304 eqslider_get_position(equalizerwin_preamp)); | |
1305 | |
1306 for (i = 0; i < 10; i++) { | |
1307 gchar tmp[7]; | |
1308 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1309 bmp_rcfile_write_float(rcfile, "Equalizer preset", tmp, | |
1310 eqslider_get_position(equalizerwin_bands[i])); | |
1311 } | |
1312 | |
1313 bmp_rcfile_write(rcfile, filename); | |
1314 bmp_rcfile_free(rcfile); | |
1315 } | |
1316 | |
1317 static void | |
1318 save_winamp_file(const gchar * filename) | |
1319 { | |
1320 VFSFile *file; | |
1321 | |
1322 gchar name[257]; | |
1323 gint i; | |
1324 guchar bands[11]; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1325 gchar *tmp; |
0 | 1326 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1327 if (!(file = vfs_fopen(filename, "wb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1328 tmp = g_strconcat("Failed to save WinAmp file: ",filename,"\n",NULL); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1329 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1330 g_free(tmp); |
0 | 1331 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1332 } |
0 | 1333 |
1334 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file); | |
1335 | |
1336 memset(name, 0, 257); | |
1337 strcpy(name, "Entry1"); | |
1338 vfs_fwrite(name, 1, 257, file); | |
1339 | |
1340 for (i = 0; i < 10; i++) | |
1341 bands[i] = 63 - (((eqslider_get_position(equalizerwin_bands[i]) + 20) * 63) / 40); | |
1342 bands[10] = 63 - (((eqslider_get_position(equalizerwin_preamp) + 20) * 63) / 40); | |
1343 vfs_fwrite(bands, 1, 11, file); | |
1344 | |
1345 vfs_fclose(file); | |
1346 } | |
1347 | |
1348 static gint | |
1349 equalizerwin_list_sort_func(GtkCList * clist, | |
1350 gconstpointer ptr1, gconstpointer ptr2) | |
1351 { | |
1352 GtkCListRow *row1 = (GtkCListRow *) ptr1; | |
1353 GtkCListRow *row2 = (GtkCListRow *) ptr2; | |
1354 | |
1355 return strcasecmp(GTK_CELL_TEXT(row1->cell[clist->sort_column])->text, | |
1356 GTK_CELL_TEXT(row2->cell[clist->sort_column])->text); | |
1357 } | |
1358 | |
1359 | |
1360 static GtkListStore * | |
1361 preset_list_store_new(GList * preset) | |
1362 { | |
1363 GtkListStore *store; | |
1364 GtkTreeIter iter; | |
1365 GList *node; | |
1366 | |
1367 store = gtk_list_store_new(PRESET_VIEW_N_COLS, G_TYPE_STRING); | |
1368 | |
1369 for (node = preset; node; node = g_list_next(node)) { | |
1370 gtk_list_store_append(store, &iter); | |
1371 gtk_list_store_set(store, &iter, | |
1372 PRESET_VIEW_COL_NAME, | |
1373 &((EqualizerPreset *) node->data)->name, -1); | |
1374 } | |
1375 | |
1376 return store; | |
1377 } | |
1378 | |
1379 | |
1380 GtkWidget * | |
1381 preset_view_new(GList * preset) | |
1382 { | |
1383 GtkWidget *treeview; | |
1384 GtkTreeModel *model; | |
1385 GtkTreeViewColumn *column; | |
1386 GtkCellRenderer *renderer; | |
1387 GtkListStore *store; | |
1388 | |
1389 store = preset_list_store_new(preset); | |
1390 | |
1391 model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store)); | |
1392 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), | |
1393 PRESET_VIEW_COL_NAME, | |
1394 GTK_SORT_ASCENDING); | |
1395 | |
1396 treeview = gtk_tree_view_new_with_model(model); | |
1397 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(treeview), TRUE); | |
1398 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); | |
1399 | |
1400 renderer = gtk_cell_renderer_text_new(); | |
1401 column = gtk_tree_view_column_new_with_attributes(_("Preset"), renderer, | |
1402 "text", | |
1403 PRESET_VIEW_COL_NAME, | |
1404 NULL); | |
1405 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
1406 | |
1407 return treeview; | |
1408 } | |
1409 | |
1410 | |
1411 static GtkWidget * | |
1412 equalizerwin_create_list_window(GList * preset_list, | |
1413 const gchar * title, | |
1414 GtkWidget ** window, | |
1415 GtkSelectionMode sel_mode, | |
1416 GtkWidget ** entry, | |
1417 const gchar * btn2_stock_name, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1418 const gchar * btn3_stock_name, |
0 | 1419 const gchar * btn1_stock_name, |
1420 GCallback btn2_func, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1421 GCallback btn3_func, |
0 | 1422 GCallback select_row_func) |
1423 { | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1424 GtkWidget *vbox, *scrolled_window, *bbox, *btn1, *btn2, *btn3, *clist; |
0 | 1425 gchar *preset_text[1]; |
1426 GList *node; | |
1427 | |
1428 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1429 gtk_window_set_title(GTK_WINDOW(*window), title); | |
1430 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
1431 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); | |
1432 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); | |
1433 gtk_container_set_border_width(GTK_CONTAINER(*window), 10); | |
1434 gtk_window_set_transient_for(GTK_WINDOW(*window), | |
1435 GTK_WINDOW(equalizerwin)); | |
1436 g_signal_connect(*window, "destroy", | |
1437 G_CALLBACK(gtk_widget_destroyed), window); | |
1438 | |
1439 vbox = gtk_vbox_new(FALSE, 10); | |
1440 gtk_container_add(GTK_CONTAINER(*window), vbox); | |
1441 | |
1442 scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
1443 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | |
1444 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1445 | |
1446 preset_text[0] = _("Presets"); | |
1447 clist = gtk_clist_new_with_titles(1, preset_text); | |
1448 if (select_row_func) | |
1449 g_signal_connect(clist, "select_row", | |
1450 G_CALLBACK(select_row_func), NULL); | |
1451 gtk_clist_column_titles_passive(GTK_CLIST(clist)); | |
1452 gtk_clist_set_selection_mode(GTK_CLIST(clist), sel_mode); | |
1453 | |
1454 for (node = preset_list; node; node = g_list_next(node)) { | |
1455 gtk_clist_append(GTK_CLIST(clist), | |
1456 &((EqualizerPreset *) node->data)->name); | |
1457 } | |
1458 gtk_clist_set_compare_func(GTK_CLIST(clist), equalizerwin_list_sort_func); | |
1459 gtk_clist_sort(GTK_CLIST(clist)); | |
1460 | |
1461 gtk_container_add(GTK_CONTAINER(scrolled_window), clist); | |
1462 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); | |
1463 | |
1464 if (entry) { | |
1465 *entry = gtk_entry_new(); | |
1466 g_signal_connect(*entry, "activate", btn2_func, NULL); | |
1467 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); | |
1468 } | |
1469 | |
1470 bbox = gtk_hbutton_box_new(); | |
1471 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1472 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1473 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1474 | |
1475 btn1 = gtk_button_new_from_stock(btn1_stock_name); | |
1476 g_signal_connect_swapped(btn1, "clicked", | |
1477 G_CALLBACK(gtk_widget_destroy), | |
1478 GTK_OBJECT(*window)); | |
1479 gtk_box_pack_start(GTK_BOX(bbox), btn1, TRUE, TRUE, 0); | |
1480 | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1481 if (btn3_stock_name) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1482 btn3 = gtk_button_new_from_stock(btn3_stock_name); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1483 g_signal_connect(btn3, "clicked", G_CALLBACK(btn3_func), clist); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1484 gtk_box_pack_start(GTK_BOX(bbox), btn3, TRUE, TRUE, 0); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1485 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1486 |
0 | 1487 btn2 = gtk_button_new_from_stock(btn2_stock_name); |
1488 g_signal_connect(btn2, "clicked", G_CALLBACK(btn2_func), clist); | |
1489 GTK_WIDGET_SET_FLAGS(btn2, GTK_CAN_DEFAULT); | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1490 |
0 | 1491 gtk_box_pack_start(GTK_BOX(bbox), btn2, TRUE, TRUE, 0); |
1492 | |
1493 gtk_widget_grab_default(btn2); | |
1494 | |
1495 | |
1496 gtk_widget_show_all(*window); | |
1497 | |
1498 return *window; | |
1499 } | |
1500 | |
1501 void | |
1502 equalizerwin_presets_menu_cb(gpointer cb_data, guint action, GtkWidget * w) | |
1503 { | |
1504 GtkWidget *dialog; | |
1505 | |
1506 switch (action) { | |
1507 case EQUALIZER_PRESETS_LOAD_PRESET: | |
1508 if (!equalizerwin_load_window) | |
1509 equalizerwin_create_list_window(equalizer_presets, | |
1510 _("Load preset"), | |
1511 &equalizerwin_load_window, | |
1512 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1513 GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, |
0 | 1514 G_CALLBACK |
1515 (equalizerwin_load_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1516 G_CALLBACK |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1517 (equalizerwin_load_apply), |
0 | 1518 G_CALLBACK |
1519 (equalizerwin_load_select)); | |
1520 else | |
1521 gtk_window_present(GTK_WINDOW(equalizerwin_load_window)); | |
1522 break; | |
1523 case EQUALIZER_PRESETS_LOAD_AUTOPRESET: | |
1524 if (!equalizerwin_load_auto_window) | |
1525 equalizerwin_create_list_window(equalizer_auto_presets, | |
1526 _("Load auto-preset"), | |
1527 &equalizerwin_load_auto_window, | |
1528 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1529 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1530 G_CALLBACK |
1531 (equalizerwin_load_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1532 NULL, |
0 | 1533 G_CALLBACK |
1534 (equalizerwin_load_auto_select)); | |
1535 else | |
1536 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window)); | |
1537 break; | |
1538 case EQUALIZER_PRESETS_LOAD_DEFAULT: | |
1539 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1540 break; | |
1541 case EQUALIZER_PRESETS_LOAD_ZERO: | |
1542 { | |
1543 gint i; | |
1544 | |
1545 eqslider_set_position(equalizerwin_preamp, 0); | |
1546 for (i = 0; i < 10; i++) | |
1547 eqslider_set_position(equalizerwin_bands[i], 0); | |
1548 equalizerwin_eq_changed(); | |
1549 break; | |
1550 } | |
1551 case EQUALIZER_PRESETS_LOAD_FROM_FILE: | |
1552 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1553 g_signal_connect(dialog , "response", | |
1554 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1555 load_preset_file); | |
1556 break; | |
1557 case EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE: | |
1558 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1559 g_signal_connect(dialog, "response", | |
1560 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1561 load_winamp_file); | |
1562 break; | |
1563 | |
1564 case EQUALIZER_PRESETS_IMPORT_WINAMPFILE: | |
1565 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1566 g_signal_connect(dialog, "response", | |
1567 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1568 import_winamp_file); | |
1569 break; | |
1570 | |
1571 case EQUALIZER_PRESETS_SAVE_PRESET: | |
1572 if (!equalizerwin_save_window) | |
1573 equalizerwin_create_list_window(equalizer_presets, | |
1574 _("Save preset"), | |
1575 &equalizerwin_save_window, | |
1576 GTK_SELECTION_SINGLE, | |
1577 &equalizerwin_save_entry, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1578 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1579 G_CALLBACK |
1580 (equalizerwin_save_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1581 NULL, |
0 | 1582 G_CALLBACK |
1583 (equalizerwin_save_select)); | |
1584 else | |
1585 gtk_window_present(GTK_WINDOW(equalizerwin_save_window)); | |
1586 break; | |
1587 | |
1588 case EQUALIZER_PRESETS_SAVE_AUTOPRESET: | |
1589 { | |
1590 gchar *name; | |
1591 | |
1592 if (!equalizerwin_save_auto_window) | |
1593 equalizerwin_create_list_window(equalizer_auto_presets, | |
1594 _("Save auto-preset"), | |
1595 &equalizerwin_save_auto_window, | |
1596 GTK_SELECTION_SINGLE, | |
1597 &equalizerwin_save_auto_entry, | |
1598 GTK_STOCK_OK, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1599 NULL, |
0 | 1600 GTK_STOCK_CANCEL, |
1601 G_CALLBACK | |
1602 (equalizerwin_save_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1603 NULL, |
0 | 1604 G_CALLBACK |
1605 (equalizerwin_save_auto_select)); | |
1606 else | |
1607 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window)); | |
1608 | |
1609 name = playlist_get_filename(playlist_get_position()); | |
1610 | |
1611 if (name) { | |
1612 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), | |
1613 g_basename(name)); | |
1614 g_free(name); | |
1615 } | |
1616 break; | |
1617 } | |
1618 | |
1619 case EQUALIZER_PRESETS_SAVE_DEFAULT: | |
1620 equalizer_presets = | |
1621 equalizerwin_save_preset(equalizer_presets, "Default", | |
1622 "eq.preset"); | |
1623 break; | |
1624 | |
1625 case EQUALIZER_PRESETS_SAVE_TO_FILE: | |
1626 { | |
1627 gchar *songname; | |
1628 | |
1629 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1630 g_signal_connect(dialog, "response", | |
1631 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1632 save_preset_file); | |
1633 | |
1634 songname = playlist_get_filename(playlist_get_position()); | |
1635 if (songname) { | |
1636 gchar *eqname = g_strdup_printf("%s.%s", songname, | |
1637 cfg.eqpreset_extension); | |
1638 g_free(songname); | |
1639 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
1640 eqname); | |
1641 g_free(eqname); | |
1642 } | |
1643 | |
1644 break; | |
1645 } | |
1646 | |
1647 case EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE: | |
1648 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1649 g_signal_connect(dialog, "response", | |
1650 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1651 save_winamp_file); | |
1652 break; | |
1653 | |
1654 case EQUALIZER_PRESETS_DELETE_PRESET: | |
1655 if (!equalizerwin_delete_window) | |
1656 equalizerwin_create_list_window(equalizer_presets, | |
1657 _("Delete preset"), | |
1658 &equalizerwin_delete_window, | |
1659 GTK_SELECTION_EXTENDED, NULL, | |
1660 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1661 NULL, |
0 | 1662 GTK_STOCK_CLOSE, |
1663 G_CALLBACK | |
1664 (equalizerwin_delete_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1665 NULL, |
0 | 1666 NULL); |
1667 else | |
1668 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window)); | |
1669 | |
1670 break; | |
1671 | |
1672 case EQUALIZER_PRESETS_DELETE_AUTOPRESET: | |
1673 if (!equalizerwin_delete_auto_window) | |
1674 equalizerwin_create_list_window(equalizer_auto_presets, | |
1675 _("Delete auto-preset"), | |
1676 &equalizerwin_delete_auto_window, | |
1677 GTK_SELECTION_EXTENDED, NULL, | |
1678 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1679 NULL, |
0 | 1680 GTK_STOCK_CLOSE, |
1681 G_CALLBACK | |
1682 (equalizerwin_delete_auto_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1683 NULL, |
0 | 1684 NULL); |
1685 else | |
1686 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window)); | |
1687 | |
1688 break; | |
1689 } | |
1690 } | |
1691 | |
1692 void | |
1693 equalizerwin_load_auto_preset(const gchar * filename) | |
1694 { | |
1695 gchar *presetfilename, *directory; | |
1696 RcFile *rcfile; | |
1697 | |
1698 g_return_if_fail(filename != NULL); | |
1699 | |
1700 if (!cfg.equalizer_autoload) | |
1701 return; | |
1702 | |
1703 presetfilename = g_strconcat(filename, ".", cfg.eqpreset_extension, NULL); | |
1704 | |
1705 /* First try to find a per file preset file */ | |
1706 if (strlen(cfg.eqpreset_extension) > 0 && | |
1707 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1708 g_free(presetfilename); | |
1709 equalizerwin_read_bmp_preset(rcfile); | |
1710 bmp_rcfile_free(rcfile); | |
1711 return; | |
1712 } | |
1713 | |
1714 g_free(presetfilename); | |
1715 | |
1716 directory = g_path_get_dirname(filename); | |
1717 presetfilename = g_build_filename(directory, cfg.eqpreset_default_file, | |
1718 NULL); | |
1719 g_free(directory); | |
1720 | |
1721 /* Try to find a per directory preset file */ | |
1722 if (strlen(cfg.eqpreset_default_file) > 0 && | |
1723 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1724 equalizerwin_read_bmp_preset(rcfile); | |
1725 bmp_rcfile_free(rcfile); | |
1726 } | |
1727 else if (!equalizerwin_load_preset | |
1728 (equalizer_auto_presets, g_basename(filename))) { | |
1729 /* Fall back to the oldstyle auto presets */ | |
1730 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1731 } | |
1732 | |
1733 g_free(presetfilename); | |
1734 } | |
1735 | |
1736 void | |
1737 equalizerwin_set_preamp(gfloat preamp) | |
1738 { | |
1739 eqslider_set_position(equalizerwin_preamp, preamp); | |
1740 equalizerwin_eq_changed(); | |
1741 } | |
1742 | |
1743 void | |
1744 equalizerwin_set_band(gint band, gfloat value) | |
1745 { | |
1746 g_return_if_fail(band >= 0 && band < 10); | |
1747 eqslider_set_position(equalizerwin_bands[band], value); | |
1748 } | |
1749 | |
1750 gfloat | |
1751 equalizerwin_get_preamp(void) | |
1752 { | |
1753 return eqslider_get_position(equalizerwin_preamp); | |
1754 } | |
1755 | |
1756 gfloat | |
1757 equalizerwin_get_band(gint band) | |
1758 { | |
1759 g_return_val_if_fail(band >= 0 && band < 10, 0); | |
1760 return eqslider_get_position(equalizerwin_bands[band]); | |
1761 } |