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