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