Mercurial > audlegacy
annotate audacious/equalizer.c @ 553:82346a6312c2 trunk
[svn] make WMA plugin strings translatable
author | nenolod |
---|---|
date | Wed, 01 Feb 2006 13:09:00 -0800 |
parents | bcbc6195e82e |
children | 0a73d1faeb4e |
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 { | |
533
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
424 GdkEvent *gevent; |
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
425 |
0 | 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 | |
533
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
435 while ((gevent = gdk_event_get()) != NULL) gdk_event_free(gevent); |
bcbc6195e82e
[svn] throw out duplicate XEvents... again, for speed purposes we don't need
nenolod
parents:
484
diff
changeset
|
436 |
0 | 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, | |
424
d7d70779c074
[svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents:
383
diff
changeset
|
691 equalizerwin_shade_toggle, NULL, SKIN_EQMAIN, SKIN_EQ_EX); |
0 | 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); | |
187 | 741 gtk_window_set_title(GTK_WINDOW(equalizerwin), _("Audacious Equalizer")); |
0 | 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 | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1091 equalizerwin_load_apply(GtkWidget * widget, gpointer data) |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1092 { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1093 gchar *text; |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1094 GtkCList *clist = GTK_CLIST(data); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1095 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1096 if (clist && clist->selection) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1097 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1098 0, &text); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1099 equalizerwin_load_preset(equalizer_presets, text); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1100 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1101 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1102 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1103 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1104 static void |
0 | 1105 equalizerwin_load_select(GtkCList * widget, gint row, |
1106 gint column, GdkEventButton * event, gpointer data) | |
1107 { | |
1108 if (event->type == GDK_2BUTTON_PRESS) | |
1109 equalizerwin_load_ok(NULL, widget); | |
1110 } | |
1111 | |
1112 static void | |
1113 equalizerwin_delete_delete(GtkWidget * widget, gpointer data) | |
1114 { | |
1115 gchar *text; | |
1116 GList *list, *next; | |
1117 GtkCList *clist = GTK_CLIST(data); | |
1118 | |
1119 g_return_if_fail(clist != NULL); | |
1120 | |
1121 list = clist->selection; | |
1122 gtk_clist_freeze(clist); | |
1123 while (list) { | |
1124 next = g_list_next(list); | |
1125 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text); | |
1126 equalizer_auto_presets = | |
1127 equalizerwin_delete_preset(equalizer_presets, text, "eq.preset"); | |
1128 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data)); | |
1129 list = next; | |
1130 } | |
1131 gtk_clist_thaw(clist); | |
1132 } | |
1133 | |
1134 static void | |
1135 equalizerwin_save_auto_ok(GtkWidget * widget, gpointer data) | |
1136 { | |
1137 const gchar *text; | |
1138 | |
1139 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_auto_entry)); | |
1140 if (strlen(text) != 0) | |
1141 equalizer_auto_presets = | |
1142 equalizerwin_save_preset(equalizer_auto_presets, text, | |
1143 "eq.auto_preset"); | |
1144 gtk_widget_destroy(equalizerwin_save_auto_window); | |
1145 } | |
1146 | |
1147 static void | |
1148 equalizerwin_save_auto_select(GtkCList * clist, gint row, | |
1149 gint column, | |
1150 GdkEventButton * event, gpointer data) | |
1151 { | |
1152 gchar *text; | |
1153 | |
1154 gtk_clist_get_text(clist, row, 0, &text); | |
1155 | |
1156 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), text); | |
1157 if (event->type == GDK_2BUTTON_PRESS) | |
1158 equalizerwin_save_auto_ok(NULL, NULL); | |
1159 | |
1160 } | |
1161 | |
1162 static void | |
1163 equalizerwin_load_auto_ok(GtkWidget * widget, gpointer data) | |
1164 { | |
1165 gchar *text; | |
1166 GtkCList *clist = GTK_CLIST(data); | |
1167 | |
1168 if (clist && clist->selection) { | |
1169 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), | |
1170 0, &text); | |
1171 equalizerwin_load_preset(equalizer_auto_presets, text); | |
1172 } | |
1173 gtk_widget_destroy(equalizerwin_load_auto_window); | |
1174 } | |
1175 | |
1176 static void | |
1177 equalizerwin_load_auto_select(GtkWidget * widget, gint row, | |
1178 gint column, | |
1179 GdkEventButton * event, gpointer data) | |
1180 { | |
1181 if (event->type == GDK_2BUTTON_PRESS) | |
1182 equalizerwin_load_auto_ok(NULL, widget); | |
1183 } | |
1184 | |
1185 static void | |
1186 equalizerwin_delete_auto_delete(GtkWidget * widget, gpointer data) | |
1187 { | |
1188 gchar *text; | |
1189 GList *list, *next; | |
1190 GtkCList *clist = GTK_CLIST(data); | |
1191 | |
1192 g_return_if_fail(clist != NULL); | |
1193 | |
1194 list = clist->selection; | |
1195 gtk_clist_freeze(clist); | |
1196 while (list) { | |
1197 next = g_list_next(list); | |
1198 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text); | |
1199 equalizer_auto_presets = | |
1200 equalizerwin_delete_preset(equalizer_auto_presets, text, | |
1201 "eq.auto_preset"); | |
1202 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data)); | |
1203 list = next; | |
1204 } | |
1205 gtk_clist_thaw(clist); | |
1206 } | |
1207 | |
1208 | |
1209 typedef void (*ResponseHandler)(const gchar *filename); | |
1210 | |
1211 static void | |
1212 equalizerwin_file_chooser_on_response(GtkWidget * dialog, | |
1213 gint response, | |
1214 gpointer data) | |
1215 { | |
1216 GtkFileChooser *file_chooser = GTK_FILE_CHOOSER(dialog); | |
1217 ResponseHandler handler = (ResponseHandler) data; | |
1218 gchar *filename; | |
1219 | |
1220 gtk_widget_hide(dialog); | |
1221 | |
1222 switch (response) | |
1223 { | |
1224 case GTK_RESPONSE_ACCEPT: | |
1225 filename = gtk_file_chooser_get_filename(file_chooser); | |
1226 handler(filename); | |
1227 g_free(filename); | |
1228 break; | |
1229 | |
1230 case GTK_RESPONSE_REJECT: | |
1231 break; | |
1232 } | |
1233 | |
1234 gtk_widget_destroy(dialog); | |
1235 } | |
1236 | |
1237 | |
1238 | |
1239 static void | |
1240 load_preset_file(const gchar *filename) | |
1241 { | |
1242 RcFile *rcfile; | |
1243 | |
1244 if ((rcfile = bmp_rcfile_open(filename)) != NULL) { | |
1245 equalizerwin_read_bmp_preset(rcfile); | |
1246 bmp_rcfile_free(rcfile); | |
1247 } | |
1248 } | |
1249 | |
1250 static void | |
1251 load_winamp_file(const gchar * filename) | |
1252 { | |
1253 VFSFile *file; | |
1254 | |
1255 /* FIXME: show error dialog */ | |
1256 if (!(file = vfs_fopen(filename, "rb"))) | |
1257 return; | |
1258 | |
1259 equalizerwin_read_winamp_eqf(file); | |
1260 vfs_fclose(file); | |
1261 } | |
1262 | |
1263 static void | |
1264 import_winamp_file(const gchar * filename) | |
1265 { | |
1266 VFSFile *file; | |
1267 | |
1268 /* FIXME: show error dialog */ | |
1269 if (!(file = vfs_fopen(filename, "rb"))) | |
1270 return; | |
1271 | |
1272 equalizer_presets = g_list_concat(equalizer_presets, | |
1273 import_winamp_eqf(file)); | |
1274 equalizerwin_write_preset_file(equalizer_presets, "eq.preset"); | |
1275 | |
1276 vfs_fclose(file); | |
1277 } | |
1278 | |
1279 static void | |
1280 save_preset_file(const gchar * filename) | |
1281 { | |
1282 RcFile *rcfile; | |
1283 gint i; | |
1284 | |
1285 rcfile = bmp_rcfile_new(); | |
1286 bmp_rcfile_write_float(rcfile, "Equalizer preset", "Preamp", | |
1287 eqslider_get_position(equalizerwin_preamp)); | |
1288 | |
1289 for (i = 0; i < 10; i++) { | |
1290 gchar tmp[7]; | |
1291 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1292 bmp_rcfile_write_float(rcfile, "Equalizer preset", tmp, | |
1293 eqslider_get_position(equalizerwin_bands[i])); | |
1294 } | |
1295 | |
1296 bmp_rcfile_write(rcfile, filename); | |
1297 bmp_rcfile_free(rcfile); | |
1298 } | |
1299 | |
1300 static void | |
1301 save_winamp_file(const gchar * filename) | |
1302 { | |
1303 VFSFile *file; | |
1304 | |
1305 gchar name[257]; | |
1306 gint i; | |
1307 guchar bands[11]; | |
1308 | |
1309 /* FIXME: show error dialog */ | |
1310 if (!(file = vfs_fopen(filename, "wb"))) | |
1311 return; | |
1312 | |
1313 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file); | |
1314 | |
1315 memset(name, 0, 257); | |
1316 strcpy(name, "Entry1"); | |
1317 vfs_fwrite(name, 1, 257, file); | |
1318 | |
1319 for (i = 0; i < 10; i++) | |
1320 bands[i] = 63 - (((eqslider_get_position(equalizerwin_bands[i]) + 20) * 63) / 40); | |
1321 bands[10] = 63 - (((eqslider_get_position(equalizerwin_preamp) + 20) * 63) / 40); | |
1322 vfs_fwrite(bands, 1, 11, file); | |
1323 | |
1324 vfs_fclose(file); | |
1325 } | |
1326 | |
1327 static gint | |
1328 equalizerwin_list_sort_func(GtkCList * clist, | |
1329 gconstpointer ptr1, gconstpointer ptr2) | |
1330 { | |
1331 GtkCListRow *row1 = (GtkCListRow *) ptr1; | |
1332 GtkCListRow *row2 = (GtkCListRow *) ptr2; | |
1333 | |
1334 return strcasecmp(GTK_CELL_TEXT(row1->cell[clist->sort_column])->text, | |
1335 GTK_CELL_TEXT(row2->cell[clist->sort_column])->text); | |
1336 } | |
1337 | |
1338 | |
1339 static GtkListStore * | |
1340 preset_list_store_new(GList * preset) | |
1341 { | |
1342 GtkListStore *store; | |
1343 GtkTreeIter iter; | |
1344 GList *node; | |
1345 | |
1346 store = gtk_list_store_new(PRESET_VIEW_N_COLS, G_TYPE_STRING); | |
1347 | |
1348 for (node = preset; node; node = g_list_next(node)) { | |
1349 gtk_list_store_append(store, &iter); | |
1350 gtk_list_store_set(store, &iter, | |
1351 PRESET_VIEW_COL_NAME, | |
1352 &((EqualizerPreset *) node->data)->name, -1); | |
1353 } | |
1354 | |
1355 return store; | |
1356 } | |
1357 | |
1358 | |
1359 GtkWidget * | |
1360 preset_view_new(GList * preset) | |
1361 { | |
1362 GtkWidget *treeview; | |
1363 GtkTreeModel *model; | |
1364 GtkTreeViewColumn *column; | |
1365 GtkCellRenderer *renderer; | |
1366 GtkListStore *store; | |
1367 | |
1368 store = preset_list_store_new(preset); | |
1369 | |
1370 model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store)); | |
1371 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), | |
1372 PRESET_VIEW_COL_NAME, | |
1373 GTK_SORT_ASCENDING); | |
1374 | |
1375 treeview = gtk_tree_view_new_with_model(model); | |
1376 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(treeview), TRUE); | |
1377 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); | |
1378 | |
1379 renderer = gtk_cell_renderer_text_new(); | |
1380 column = gtk_tree_view_column_new_with_attributes(_("Preset"), renderer, | |
1381 "text", | |
1382 PRESET_VIEW_COL_NAME, | |
1383 NULL); | |
1384 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
1385 | |
1386 return treeview; | |
1387 } | |
1388 | |
1389 | |
1390 static GtkWidget * | |
1391 equalizerwin_create_list_window(GList * preset_list, | |
1392 const gchar * title, | |
1393 GtkWidget ** window, | |
1394 GtkSelectionMode sel_mode, | |
1395 GtkWidget ** entry, | |
1396 const gchar * btn2_stock_name, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1397 const gchar * btn3_stock_name, |
0 | 1398 const gchar * btn1_stock_name, |
1399 GCallback btn2_func, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1400 GCallback btn3_func, |
0 | 1401 GCallback select_row_func) |
1402 { | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1403 GtkWidget *vbox, *scrolled_window, *bbox, *btn1, *btn2, *btn3, *clist; |
0 | 1404 gchar *preset_text[1]; |
1405 GList *node; | |
1406 | |
1407 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1408 gtk_window_set_title(GTK_WINDOW(*window), title); | |
1409 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
1410 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); | |
1411 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); | |
1412 gtk_container_set_border_width(GTK_CONTAINER(*window), 10); | |
1413 gtk_window_set_transient_for(GTK_WINDOW(*window), | |
1414 GTK_WINDOW(equalizerwin)); | |
1415 g_signal_connect(*window, "destroy", | |
1416 G_CALLBACK(gtk_widget_destroyed), window); | |
1417 | |
1418 vbox = gtk_vbox_new(FALSE, 10); | |
1419 gtk_container_add(GTK_CONTAINER(*window), vbox); | |
1420 | |
1421 scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
1422 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | |
1423 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1424 | |
1425 preset_text[0] = _("Presets"); | |
1426 clist = gtk_clist_new_with_titles(1, preset_text); | |
1427 if (select_row_func) | |
1428 g_signal_connect(clist, "select_row", | |
1429 G_CALLBACK(select_row_func), NULL); | |
1430 gtk_clist_column_titles_passive(GTK_CLIST(clist)); | |
1431 gtk_clist_set_selection_mode(GTK_CLIST(clist), sel_mode); | |
1432 | |
1433 for (node = preset_list; node; node = g_list_next(node)) { | |
1434 gtk_clist_append(GTK_CLIST(clist), | |
1435 &((EqualizerPreset *) node->data)->name); | |
1436 } | |
1437 gtk_clist_set_compare_func(GTK_CLIST(clist), equalizerwin_list_sort_func); | |
1438 gtk_clist_sort(GTK_CLIST(clist)); | |
1439 | |
1440 gtk_container_add(GTK_CONTAINER(scrolled_window), clist); | |
1441 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); | |
1442 | |
1443 if (entry) { | |
1444 *entry = gtk_entry_new(); | |
1445 g_signal_connect(*entry, "activate", btn2_func, NULL); | |
1446 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); | |
1447 } | |
1448 | |
1449 bbox = gtk_hbutton_box_new(); | |
1450 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1451 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1452 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1453 | |
1454 btn1 = gtk_button_new_from_stock(btn1_stock_name); | |
1455 g_signal_connect_swapped(btn1, "clicked", | |
1456 G_CALLBACK(gtk_widget_destroy), | |
1457 GTK_OBJECT(*window)); | |
1458 gtk_box_pack_start(GTK_BOX(bbox), btn1, TRUE, TRUE, 0); | |
1459 | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1460 if (btn3_stock_name) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1461 btn3 = gtk_button_new_from_stock(btn3_stock_name); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1462 g_signal_connect(btn3, "clicked", G_CALLBACK(btn3_func), clist); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1463 gtk_box_pack_start(GTK_BOX(bbox), btn3, TRUE, TRUE, 0); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1464 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1465 |
0 | 1466 btn2 = gtk_button_new_from_stock(btn2_stock_name); |
1467 g_signal_connect(btn2, "clicked", G_CALLBACK(btn2_func), clist); | |
1468 GTK_WIDGET_SET_FLAGS(btn2, GTK_CAN_DEFAULT); | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1469 |
0 | 1470 gtk_box_pack_start(GTK_BOX(bbox), btn2, TRUE, TRUE, 0); |
1471 | |
1472 gtk_widget_grab_default(btn2); | |
1473 | |
1474 | |
1475 gtk_widget_show_all(*window); | |
1476 | |
1477 return *window; | |
1478 } | |
1479 | |
1480 void | |
1481 equalizerwin_presets_menu_cb(gpointer cb_data, guint action, GtkWidget * w) | |
1482 { | |
1483 GtkWidget *dialog; | |
1484 | |
1485 switch (action) { | |
1486 case EQUALIZER_PRESETS_LOAD_PRESET: | |
1487 if (!equalizerwin_load_window) | |
1488 equalizerwin_create_list_window(equalizer_presets, | |
1489 _("Load preset"), | |
1490 &equalizerwin_load_window, | |
1491 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1492 GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, |
0 | 1493 G_CALLBACK |
1494 (equalizerwin_load_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1495 G_CALLBACK |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1496 (equalizerwin_load_apply), |
0 | 1497 G_CALLBACK |
1498 (equalizerwin_load_select)); | |
1499 else | |
1500 gtk_window_present(GTK_WINDOW(equalizerwin_load_window)); | |
1501 break; | |
1502 case EQUALIZER_PRESETS_LOAD_AUTOPRESET: | |
1503 if (!equalizerwin_load_auto_window) | |
1504 equalizerwin_create_list_window(equalizer_auto_presets, | |
1505 _("Load auto-preset"), | |
1506 &equalizerwin_load_auto_window, | |
1507 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1508 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1509 G_CALLBACK |
1510 (equalizerwin_load_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1511 NULL, |
0 | 1512 G_CALLBACK |
1513 (equalizerwin_load_auto_select)); | |
1514 else | |
1515 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window)); | |
1516 break; | |
1517 case EQUALIZER_PRESETS_LOAD_DEFAULT: | |
1518 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1519 break; | |
1520 case EQUALIZER_PRESETS_LOAD_ZERO: | |
1521 { | |
1522 gint i; | |
1523 | |
1524 eqslider_set_position(equalizerwin_preamp, 0); | |
1525 for (i = 0; i < 10; i++) | |
1526 eqslider_set_position(equalizerwin_bands[i], 0); | |
1527 equalizerwin_eq_changed(); | |
1528 break; | |
1529 } | |
1530 case EQUALIZER_PRESETS_LOAD_FROM_FILE: | |
1531 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1532 g_signal_connect(dialog , "response", | |
1533 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1534 load_preset_file); | |
1535 break; | |
1536 case EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE: | |
1537 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1538 g_signal_connect(dialog, "response", | |
1539 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1540 load_winamp_file); | |
1541 break; | |
1542 | |
1543 case EQUALIZER_PRESETS_IMPORT_WINAMPFILE: | |
1544 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1545 g_signal_connect(dialog, "response", | |
1546 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1547 import_winamp_file); | |
1548 break; | |
1549 | |
1550 case EQUALIZER_PRESETS_SAVE_PRESET: | |
1551 if (!equalizerwin_save_window) | |
1552 equalizerwin_create_list_window(equalizer_presets, | |
1553 _("Save preset"), | |
1554 &equalizerwin_save_window, | |
1555 GTK_SELECTION_SINGLE, | |
1556 &equalizerwin_save_entry, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1557 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1558 G_CALLBACK |
1559 (equalizerwin_save_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1560 NULL, |
0 | 1561 G_CALLBACK |
1562 (equalizerwin_save_select)); | |
1563 else | |
1564 gtk_window_present(GTK_WINDOW(equalizerwin_save_window)); | |
1565 break; | |
1566 | |
1567 case EQUALIZER_PRESETS_SAVE_AUTOPRESET: | |
1568 { | |
1569 gchar *name; | |
1570 | |
1571 if (!equalizerwin_save_auto_window) | |
1572 equalizerwin_create_list_window(equalizer_auto_presets, | |
1573 _("Save auto-preset"), | |
1574 &equalizerwin_save_auto_window, | |
1575 GTK_SELECTION_SINGLE, | |
1576 &equalizerwin_save_auto_entry, | |
1577 GTK_STOCK_OK, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1578 NULL, |
0 | 1579 GTK_STOCK_CANCEL, |
1580 G_CALLBACK | |
1581 (equalizerwin_save_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1582 NULL, |
0 | 1583 G_CALLBACK |
1584 (equalizerwin_save_auto_select)); | |
1585 else | |
1586 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window)); | |
1587 | |
1588 name = playlist_get_filename(playlist_get_position()); | |
1589 | |
1590 if (name) { | |
1591 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), | |
1592 g_basename(name)); | |
1593 g_free(name); | |
1594 } | |
1595 break; | |
1596 } | |
1597 | |
1598 case EQUALIZER_PRESETS_SAVE_DEFAULT: | |
1599 equalizer_presets = | |
1600 equalizerwin_save_preset(equalizer_presets, "Default", | |
1601 "eq.preset"); | |
1602 break; | |
1603 | |
1604 case EQUALIZER_PRESETS_SAVE_TO_FILE: | |
1605 { | |
1606 gchar *songname; | |
1607 | |
1608 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1609 g_signal_connect(dialog, "response", | |
1610 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1611 save_preset_file); | |
1612 | |
1613 songname = playlist_get_filename(playlist_get_position()); | |
1614 if (songname) { | |
1615 gchar *eqname = g_strdup_printf("%s.%s", songname, | |
1616 cfg.eqpreset_extension); | |
1617 g_free(songname); | |
1618 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
1619 eqname); | |
1620 g_free(eqname); | |
1621 } | |
1622 | |
1623 break; | |
1624 } | |
1625 | |
1626 case EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE: | |
1627 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1628 g_signal_connect(dialog, "response", | |
1629 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1630 save_winamp_file); | |
1631 break; | |
1632 | |
1633 case EQUALIZER_PRESETS_DELETE_PRESET: | |
1634 if (!equalizerwin_delete_window) | |
1635 equalizerwin_create_list_window(equalizer_presets, | |
1636 _("Delete preset"), | |
1637 &equalizerwin_delete_window, | |
1638 GTK_SELECTION_EXTENDED, NULL, | |
1639 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1640 NULL, |
0 | 1641 GTK_STOCK_CLOSE, |
1642 G_CALLBACK | |
1643 (equalizerwin_delete_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1644 NULL, |
0 | 1645 NULL); |
1646 else | |
1647 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window)); | |
1648 | |
1649 break; | |
1650 | |
1651 case EQUALIZER_PRESETS_DELETE_AUTOPRESET: | |
1652 if (!equalizerwin_delete_auto_window) | |
1653 equalizerwin_create_list_window(equalizer_auto_presets, | |
1654 _("Delete auto-preset"), | |
1655 &equalizerwin_delete_auto_window, | |
1656 GTK_SELECTION_EXTENDED, NULL, | |
1657 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1658 NULL, |
0 | 1659 GTK_STOCK_CLOSE, |
1660 G_CALLBACK | |
1661 (equalizerwin_delete_auto_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1662 NULL, |
0 | 1663 NULL); |
1664 else | |
1665 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window)); | |
1666 | |
1667 break; | |
1668 } | |
1669 } | |
1670 | |
1671 void | |
1672 equalizerwin_load_auto_preset(const gchar * filename) | |
1673 { | |
1674 gchar *presetfilename, *directory; | |
1675 RcFile *rcfile; | |
1676 | |
1677 g_return_if_fail(filename != NULL); | |
1678 | |
1679 if (!cfg.equalizer_autoload) | |
1680 return; | |
1681 | |
1682 presetfilename = g_strconcat(filename, ".", cfg.eqpreset_extension, NULL); | |
1683 | |
1684 /* First try to find a per file preset file */ | |
1685 if (strlen(cfg.eqpreset_extension) > 0 && | |
1686 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1687 g_free(presetfilename); | |
1688 equalizerwin_read_bmp_preset(rcfile); | |
1689 bmp_rcfile_free(rcfile); | |
1690 return; | |
1691 } | |
1692 | |
1693 g_free(presetfilename); | |
1694 | |
1695 directory = g_path_get_dirname(filename); | |
1696 presetfilename = g_build_filename(directory, cfg.eqpreset_default_file, | |
1697 NULL); | |
1698 g_free(directory); | |
1699 | |
1700 /* Try to find a per directory preset file */ | |
1701 if (strlen(cfg.eqpreset_default_file) > 0 && | |
1702 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1703 equalizerwin_read_bmp_preset(rcfile); | |
1704 bmp_rcfile_free(rcfile); | |
1705 } | |
1706 else if (!equalizerwin_load_preset | |
1707 (equalizer_auto_presets, g_basename(filename))) { | |
1708 /* Fall back to the oldstyle auto presets */ | |
1709 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1710 } | |
1711 | |
1712 g_free(presetfilename); | |
1713 } | |
1714 | |
1715 void | |
1716 equalizerwin_set_preamp(gfloat preamp) | |
1717 { | |
1718 eqslider_set_position(equalizerwin_preamp, preamp); | |
1719 equalizerwin_eq_changed(); | |
1720 } | |
1721 | |
1722 void | |
1723 equalizerwin_set_band(gint band, gfloat value) | |
1724 { | |
1725 g_return_if_fail(band >= 0 && band < 10); | |
1726 eqslider_set_position(equalizerwin_bands[band], value); | |
1727 } | |
1728 | |
1729 gfloat | |
1730 equalizerwin_get_preamp(void) | |
1731 { | |
1732 return eqslider_get_position(equalizerwin_preamp); | |
1733 } | |
1734 | |
1735 gfloat | |
1736 equalizerwin_get_band(gint band) | |
1737 { | |
1738 g_return_val_if_fail(band >= 0 && band < 10, 0); | |
1739 return eqslider_get_position(equalizerwin_bands[band]); | |
1740 } |