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