Mercurial > audlegacy
annotate audacious/equalizer.c @ 913:dff18ce367ab trunk
[svn] object files in Plugins/General/scrobbler/tags/ should be deleted too on clean requests
author | giacomo |
---|---|
date | Sun, 02 Apr 2006 17:53:30 -0700 |
parents | 12c47704b4b5 |
children | 386cda529c28 |
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[] = { | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
126 {N_("/Load"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 127 {N_("/Load/Preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
128 EQUALIZER_PRESETS_LOAD_PRESET, "<Item>", NULL}, |
0 | 129 {N_("/Load/Auto-load preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
130 EQUALIZER_PRESETS_LOAD_AUTOPRESET, "<Item>", NULL}, |
0 | 131 {N_("/Load/Default"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
132 EQUALIZER_PRESETS_LOAD_DEFAULT, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
133 {"/Load/-", NULL, NULL, 0, "<Separator>", NULL}, |
0 | 134 {N_("/Load/Zero"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
135 EQUALIZER_PRESETS_LOAD_ZERO, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
136 {"/Load/-", NULL, NULL, 0, "<Separator>", NULL}, |
0 | 137 {N_("/Load/From file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
138 EQUALIZER_PRESETS_LOAD_FROM_FILE, "<Item>", NULL}, |
0 | 139 {N_("/Load/From WinAMP EQF file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
140 EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
141 {N_("/Import"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 142 {N_("/Import/WinAMP Presets"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
143 EQUALIZER_PRESETS_IMPORT_WINAMPFILE, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
144 {N_("/Save"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 145 {N_("/Save/Preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
146 EQUALIZER_PRESETS_SAVE_PRESET, "<Item>", NULL}, |
0 | 147 {N_("/Save/Auto-load preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
148 EQUALIZER_PRESETS_SAVE_AUTOPRESET, "<Item>", NULL}, |
0 | 149 {N_("/Save/Default"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
150 EQUALIZER_PRESETS_SAVE_DEFAULT, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
151 {"/Save/-", NULL, NULL, 0, "<Separator>", NULL}, |
0 | 152 {N_("/Save/To file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
153 EQUALIZER_PRESETS_SAVE_TO_FILE, "<Item>", NULL}, |
0 | 154 {N_("/Save/To WinAMP EQF file"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
155 EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE, "<Item>", NULL}, |
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
156 {N_("/Delete"), NULL, NULL, 0, "<Branch>", NULL}, |
0 | 157 {N_("/Delete/Preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
158 EQUALIZER_PRESETS_DELETE_PRESET, "<Item>", NULL}, |
0 | 159 {N_("/Delete/Auto-load preset"), NULL, equalizerwin_presets_menu_cb, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
533
diff
changeset
|
160 EQUALIZER_PRESETS_DELETE_AUTOPRESET, "<Item>", NULL}, |
0 | 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; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1254 gchar *tmp; |
0 | 1255 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1256 if (!(file = vfs_fopen(filename, "rb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1257 tmp = g_strconcat("Failed to load WinAmp file: ",filename,"\n",NULL); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1258 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1259 g_free(tmp); |
0 | 1260 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1261 } |
0 | 1262 |
1263 equalizerwin_read_winamp_eqf(file); | |
1264 vfs_fclose(file); | |
1265 } | |
1266 | |
1267 static void | |
1268 import_winamp_file(const gchar * filename) | |
1269 { | |
1270 VFSFile *file; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1271 gchar *tmp; |
0 | 1272 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1273 if (!(file = vfs_fopen(filename, "rb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1274 tmp = g_strconcat("Failed to import WinAmp file: ",filename,"\n",NULL); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1275 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1276 g_free(tmp); |
0 | 1277 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1278 } |
0 | 1279 |
1280 equalizer_presets = g_list_concat(equalizer_presets, | |
1281 import_winamp_eqf(file)); | |
1282 equalizerwin_write_preset_file(equalizer_presets, "eq.preset"); | |
1283 | |
1284 vfs_fclose(file); | |
1285 } | |
1286 | |
1287 static void | |
1288 save_preset_file(const gchar * filename) | |
1289 { | |
1290 RcFile *rcfile; | |
1291 gint i; | |
1292 | |
1293 rcfile = bmp_rcfile_new(); | |
1294 bmp_rcfile_write_float(rcfile, "Equalizer preset", "Preamp", | |
1295 eqslider_get_position(equalizerwin_preamp)); | |
1296 | |
1297 for (i = 0; i < 10; i++) { | |
1298 gchar tmp[7]; | |
1299 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1300 bmp_rcfile_write_float(rcfile, "Equalizer preset", tmp, | |
1301 eqslider_get_position(equalizerwin_bands[i])); | |
1302 } | |
1303 | |
1304 bmp_rcfile_write(rcfile, filename); | |
1305 bmp_rcfile_free(rcfile); | |
1306 } | |
1307 | |
1308 static void | |
1309 save_winamp_file(const gchar * filename) | |
1310 { | |
1311 VFSFile *file; | |
1312 | |
1313 gchar name[257]; | |
1314 gint i; | |
1315 guchar bands[11]; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1316 gchar *tmp; |
0 | 1317 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1318 if (!(file = vfs_fopen(filename, "wb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1319 tmp = g_strconcat("Failed to save WinAmp file: ",filename,"\n",NULL); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1320 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1321 g_free(tmp); |
0 | 1322 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1323 } |
0 | 1324 |
1325 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file); | |
1326 | |
1327 memset(name, 0, 257); | |
1328 strcpy(name, "Entry1"); | |
1329 vfs_fwrite(name, 1, 257, file); | |
1330 | |
1331 for (i = 0; i < 10; i++) | |
1332 bands[i] = 63 - (((eqslider_get_position(equalizerwin_bands[i]) + 20) * 63) / 40); | |
1333 bands[10] = 63 - (((eqslider_get_position(equalizerwin_preamp) + 20) * 63) / 40); | |
1334 vfs_fwrite(bands, 1, 11, file); | |
1335 | |
1336 vfs_fclose(file); | |
1337 } | |
1338 | |
1339 static gint | |
1340 equalizerwin_list_sort_func(GtkCList * clist, | |
1341 gconstpointer ptr1, gconstpointer ptr2) | |
1342 { | |
1343 GtkCListRow *row1 = (GtkCListRow *) ptr1; | |
1344 GtkCListRow *row2 = (GtkCListRow *) ptr2; | |
1345 | |
1346 return strcasecmp(GTK_CELL_TEXT(row1->cell[clist->sort_column])->text, | |
1347 GTK_CELL_TEXT(row2->cell[clist->sort_column])->text); | |
1348 } | |
1349 | |
1350 | |
1351 static GtkListStore * | |
1352 preset_list_store_new(GList * preset) | |
1353 { | |
1354 GtkListStore *store; | |
1355 GtkTreeIter iter; | |
1356 GList *node; | |
1357 | |
1358 store = gtk_list_store_new(PRESET_VIEW_N_COLS, G_TYPE_STRING); | |
1359 | |
1360 for (node = preset; node; node = g_list_next(node)) { | |
1361 gtk_list_store_append(store, &iter); | |
1362 gtk_list_store_set(store, &iter, | |
1363 PRESET_VIEW_COL_NAME, | |
1364 &((EqualizerPreset *) node->data)->name, -1); | |
1365 } | |
1366 | |
1367 return store; | |
1368 } | |
1369 | |
1370 | |
1371 GtkWidget * | |
1372 preset_view_new(GList * preset) | |
1373 { | |
1374 GtkWidget *treeview; | |
1375 GtkTreeModel *model; | |
1376 GtkTreeViewColumn *column; | |
1377 GtkCellRenderer *renderer; | |
1378 GtkListStore *store; | |
1379 | |
1380 store = preset_list_store_new(preset); | |
1381 | |
1382 model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store)); | |
1383 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), | |
1384 PRESET_VIEW_COL_NAME, | |
1385 GTK_SORT_ASCENDING); | |
1386 | |
1387 treeview = gtk_tree_view_new_with_model(model); | |
1388 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(treeview), TRUE); | |
1389 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); | |
1390 | |
1391 renderer = gtk_cell_renderer_text_new(); | |
1392 column = gtk_tree_view_column_new_with_attributes(_("Preset"), renderer, | |
1393 "text", | |
1394 PRESET_VIEW_COL_NAME, | |
1395 NULL); | |
1396 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
1397 | |
1398 return treeview; | |
1399 } | |
1400 | |
1401 | |
1402 static GtkWidget * | |
1403 equalizerwin_create_list_window(GList * preset_list, | |
1404 const gchar * title, | |
1405 GtkWidget ** window, | |
1406 GtkSelectionMode sel_mode, | |
1407 GtkWidget ** entry, | |
1408 const gchar * btn2_stock_name, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1409 const gchar * btn3_stock_name, |
0 | 1410 const gchar * btn1_stock_name, |
1411 GCallback btn2_func, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1412 GCallback btn3_func, |
0 | 1413 GCallback select_row_func) |
1414 { | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1415 GtkWidget *vbox, *scrolled_window, *bbox, *btn1, *btn2, *btn3, *clist; |
0 | 1416 gchar *preset_text[1]; |
1417 GList *node; | |
1418 | |
1419 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1420 gtk_window_set_title(GTK_WINDOW(*window), title); | |
1421 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
1422 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); | |
1423 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); | |
1424 gtk_container_set_border_width(GTK_CONTAINER(*window), 10); | |
1425 gtk_window_set_transient_for(GTK_WINDOW(*window), | |
1426 GTK_WINDOW(equalizerwin)); | |
1427 g_signal_connect(*window, "destroy", | |
1428 G_CALLBACK(gtk_widget_destroyed), window); | |
1429 | |
1430 vbox = gtk_vbox_new(FALSE, 10); | |
1431 gtk_container_add(GTK_CONTAINER(*window), vbox); | |
1432 | |
1433 scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
1434 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | |
1435 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1436 | |
1437 preset_text[0] = _("Presets"); | |
1438 clist = gtk_clist_new_with_titles(1, preset_text); | |
1439 if (select_row_func) | |
1440 g_signal_connect(clist, "select_row", | |
1441 G_CALLBACK(select_row_func), NULL); | |
1442 gtk_clist_column_titles_passive(GTK_CLIST(clist)); | |
1443 gtk_clist_set_selection_mode(GTK_CLIST(clist), sel_mode); | |
1444 | |
1445 for (node = preset_list; node; node = g_list_next(node)) { | |
1446 gtk_clist_append(GTK_CLIST(clist), | |
1447 &((EqualizerPreset *) node->data)->name); | |
1448 } | |
1449 gtk_clist_set_compare_func(GTK_CLIST(clist), equalizerwin_list_sort_func); | |
1450 gtk_clist_sort(GTK_CLIST(clist)); | |
1451 | |
1452 gtk_container_add(GTK_CONTAINER(scrolled_window), clist); | |
1453 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); | |
1454 | |
1455 if (entry) { | |
1456 *entry = gtk_entry_new(); | |
1457 g_signal_connect(*entry, "activate", btn2_func, NULL); | |
1458 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); | |
1459 } | |
1460 | |
1461 bbox = gtk_hbutton_box_new(); | |
1462 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1463 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1464 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1465 | |
1466 btn1 = gtk_button_new_from_stock(btn1_stock_name); | |
1467 g_signal_connect_swapped(btn1, "clicked", | |
1468 G_CALLBACK(gtk_widget_destroy), | |
1469 GTK_OBJECT(*window)); | |
1470 gtk_box_pack_start(GTK_BOX(bbox), btn1, TRUE, TRUE, 0); | |
1471 | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1472 if (btn3_stock_name) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1473 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
|
1474 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
|
1475 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
|
1476 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1477 |
0 | 1478 btn2 = gtk_button_new_from_stock(btn2_stock_name); |
1479 g_signal_connect(btn2, "clicked", G_CALLBACK(btn2_func), clist); | |
1480 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
|
1481 |
0 | 1482 gtk_box_pack_start(GTK_BOX(bbox), btn2, TRUE, TRUE, 0); |
1483 | |
1484 gtk_widget_grab_default(btn2); | |
1485 | |
1486 | |
1487 gtk_widget_show_all(*window); | |
1488 | |
1489 return *window; | |
1490 } | |
1491 | |
1492 void | |
1493 equalizerwin_presets_menu_cb(gpointer cb_data, guint action, GtkWidget * w) | |
1494 { | |
1495 GtkWidget *dialog; | |
1496 | |
1497 switch (action) { | |
1498 case EQUALIZER_PRESETS_LOAD_PRESET: | |
1499 if (!equalizerwin_load_window) | |
1500 equalizerwin_create_list_window(equalizer_presets, | |
1501 _("Load preset"), | |
1502 &equalizerwin_load_window, | |
1503 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1504 GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, |
0 | 1505 G_CALLBACK |
1506 (equalizerwin_load_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1507 G_CALLBACK |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1508 (equalizerwin_load_apply), |
0 | 1509 G_CALLBACK |
1510 (equalizerwin_load_select)); | |
1511 else | |
1512 gtk_window_present(GTK_WINDOW(equalizerwin_load_window)); | |
1513 break; | |
1514 case EQUALIZER_PRESETS_LOAD_AUTOPRESET: | |
1515 if (!equalizerwin_load_auto_window) | |
1516 equalizerwin_create_list_window(equalizer_auto_presets, | |
1517 _("Load auto-preset"), | |
1518 &equalizerwin_load_auto_window, | |
1519 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1520 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1521 G_CALLBACK |
1522 (equalizerwin_load_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1523 NULL, |
0 | 1524 G_CALLBACK |
1525 (equalizerwin_load_auto_select)); | |
1526 else | |
1527 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window)); | |
1528 break; | |
1529 case EQUALIZER_PRESETS_LOAD_DEFAULT: | |
1530 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1531 break; | |
1532 case EQUALIZER_PRESETS_LOAD_ZERO: | |
1533 { | |
1534 gint i; | |
1535 | |
1536 eqslider_set_position(equalizerwin_preamp, 0); | |
1537 for (i = 0; i < 10; i++) | |
1538 eqslider_set_position(equalizerwin_bands[i], 0); | |
1539 equalizerwin_eq_changed(); | |
1540 break; | |
1541 } | |
1542 case EQUALIZER_PRESETS_LOAD_FROM_FILE: | |
1543 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1544 g_signal_connect(dialog , "response", | |
1545 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1546 load_preset_file); | |
1547 break; | |
1548 case EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE: | |
1549 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1550 g_signal_connect(dialog, "response", | |
1551 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1552 load_winamp_file); | |
1553 break; | |
1554 | |
1555 case EQUALIZER_PRESETS_IMPORT_WINAMPFILE: | |
1556 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1557 g_signal_connect(dialog, "response", | |
1558 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1559 import_winamp_file); | |
1560 break; | |
1561 | |
1562 case EQUALIZER_PRESETS_SAVE_PRESET: | |
1563 if (!equalizerwin_save_window) | |
1564 equalizerwin_create_list_window(equalizer_presets, | |
1565 _("Save preset"), | |
1566 &equalizerwin_save_window, | |
1567 GTK_SELECTION_SINGLE, | |
1568 &equalizerwin_save_entry, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1569 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1570 G_CALLBACK |
1571 (equalizerwin_save_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1572 NULL, |
0 | 1573 G_CALLBACK |
1574 (equalizerwin_save_select)); | |
1575 else | |
1576 gtk_window_present(GTK_WINDOW(equalizerwin_save_window)); | |
1577 break; | |
1578 | |
1579 case EQUALIZER_PRESETS_SAVE_AUTOPRESET: | |
1580 { | |
1581 gchar *name; | |
1582 | |
1583 if (!equalizerwin_save_auto_window) | |
1584 equalizerwin_create_list_window(equalizer_auto_presets, | |
1585 _("Save auto-preset"), | |
1586 &equalizerwin_save_auto_window, | |
1587 GTK_SELECTION_SINGLE, | |
1588 &equalizerwin_save_auto_entry, | |
1589 GTK_STOCK_OK, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1590 NULL, |
0 | 1591 GTK_STOCK_CANCEL, |
1592 G_CALLBACK | |
1593 (equalizerwin_save_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1594 NULL, |
0 | 1595 G_CALLBACK |
1596 (equalizerwin_save_auto_select)); | |
1597 else | |
1598 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window)); | |
1599 | |
1600 name = playlist_get_filename(playlist_get_position()); | |
1601 | |
1602 if (name) { | |
1603 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), | |
1604 g_basename(name)); | |
1605 g_free(name); | |
1606 } | |
1607 break; | |
1608 } | |
1609 | |
1610 case EQUALIZER_PRESETS_SAVE_DEFAULT: | |
1611 equalizer_presets = | |
1612 equalizerwin_save_preset(equalizer_presets, "Default", | |
1613 "eq.preset"); | |
1614 break; | |
1615 | |
1616 case EQUALIZER_PRESETS_SAVE_TO_FILE: | |
1617 { | |
1618 gchar *songname; | |
1619 | |
1620 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1621 g_signal_connect(dialog, "response", | |
1622 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1623 save_preset_file); | |
1624 | |
1625 songname = playlist_get_filename(playlist_get_position()); | |
1626 if (songname) { | |
1627 gchar *eqname = g_strdup_printf("%s.%s", songname, | |
1628 cfg.eqpreset_extension); | |
1629 g_free(songname); | |
1630 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
1631 eqname); | |
1632 g_free(eqname); | |
1633 } | |
1634 | |
1635 break; | |
1636 } | |
1637 | |
1638 case EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE: | |
1639 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1640 g_signal_connect(dialog, "response", | |
1641 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1642 save_winamp_file); | |
1643 break; | |
1644 | |
1645 case EQUALIZER_PRESETS_DELETE_PRESET: | |
1646 if (!equalizerwin_delete_window) | |
1647 equalizerwin_create_list_window(equalizer_presets, | |
1648 _("Delete preset"), | |
1649 &equalizerwin_delete_window, | |
1650 GTK_SELECTION_EXTENDED, NULL, | |
1651 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1652 NULL, |
0 | 1653 GTK_STOCK_CLOSE, |
1654 G_CALLBACK | |
1655 (equalizerwin_delete_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1656 NULL, |
0 | 1657 NULL); |
1658 else | |
1659 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window)); | |
1660 | |
1661 break; | |
1662 | |
1663 case EQUALIZER_PRESETS_DELETE_AUTOPRESET: | |
1664 if (!equalizerwin_delete_auto_window) | |
1665 equalizerwin_create_list_window(equalizer_auto_presets, | |
1666 _("Delete auto-preset"), | |
1667 &equalizerwin_delete_auto_window, | |
1668 GTK_SELECTION_EXTENDED, NULL, | |
1669 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1670 NULL, |
0 | 1671 GTK_STOCK_CLOSE, |
1672 G_CALLBACK | |
1673 (equalizerwin_delete_auto_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1674 NULL, |
0 | 1675 NULL); |
1676 else | |
1677 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window)); | |
1678 | |
1679 break; | |
1680 } | |
1681 } | |
1682 | |
1683 void | |
1684 equalizerwin_load_auto_preset(const gchar * filename) | |
1685 { | |
1686 gchar *presetfilename, *directory; | |
1687 RcFile *rcfile; | |
1688 | |
1689 g_return_if_fail(filename != NULL); | |
1690 | |
1691 if (!cfg.equalizer_autoload) | |
1692 return; | |
1693 | |
1694 presetfilename = g_strconcat(filename, ".", cfg.eqpreset_extension, NULL); | |
1695 | |
1696 /* First try to find a per file preset file */ | |
1697 if (strlen(cfg.eqpreset_extension) > 0 && | |
1698 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1699 g_free(presetfilename); | |
1700 equalizerwin_read_bmp_preset(rcfile); | |
1701 bmp_rcfile_free(rcfile); | |
1702 return; | |
1703 } | |
1704 | |
1705 g_free(presetfilename); | |
1706 | |
1707 directory = g_path_get_dirname(filename); | |
1708 presetfilename = g_build_filename(directory, cfg.eqpreset_default_file, | |
1709 NULL); | |
1710 g_free(directory); | |
1711 | |
1712 /* Try to find a per directory preset file */ | |
1713 if (strlen(cfg.eqpreset_default_file) > 0 && | |
1714 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1715 equalizerwin_read_bmp_preset(rcfile); | |
1716 bmp_rcfile_free(rcfile); | |
1717 } | |
1718 else if (!equalizerwin_load_preset | |
1719 (equalizer_auto_presets, g_basename(filename))) { | |
1720 /* Fall back to the oldstyle auto presets */ | |
1721 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1722 } | |
1723 | |
1724 g_free(presetfilename); | |
1725 } | |
1726 | |
1727 void | |
1728 equalizerwin_set_preamp(gfloat preamp) | |
1729 { | |
1730 eqslider_set_position(equalizerwin_preamp, preamp); | |
1731 equalizerwin_eq_changed(); | |
1732 } | |
1733 | |
1734 void | |
1735 equalizerwin_set_band(gint band, gfloat value) | |
1736 { | |
1737 g_return_if_fail(band >= 0 && band < 10); | |
1738 eqslider_set_position(equalizerwin_bands[band], value); | |
1739 } | |
1740 | |
1741 gfloat | |
1742 equalizerwin_get_preamp(void) | |
1743 { | |
1744 return eqslider_get_position(equalizerwin_preamp); | |
1745 } | |
1746 | |
1747 gfloat | |
1748 equalizerwin_get_band(gint band) | |
1749 { | |
1750 g_return_val_if_fail(band >= 0 && band < 10, 0); | |
1751 return eqslider_get_position(equalizerwin_bands[band]); | |
1752 } |