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