Mercurial > audlegacy-plugins
annotate src/skins/ui_equalizer.c @ 2719:51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Fri, 20 Jun 2008 21:26:12 +0200 |
parents | 59af999361d8 |
children | b7d8e6fd4644 |
rev | line source |
---|---|
2606 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team. | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 3 of the License. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
21 * | |
22 * The Audacious team does not consider modular code linking to | |
23 * Audacious or using our public API to be a derived work. | |
24 */ | |
25 | |
26 /*#define AUD_DEBUG*/ | |
27 | |
28 #ifdef HAVE_CONFIG_H | |
29 # include "config.h" | |
30 #endif | |
31 | |
32 #include "ui_equalizer.h" | |
33 | |
34 #include <glib.h> | |
35 #include <glib/gi18n.h> | |
36 #include <gtk/gtk.h> | |
37 #include <stdio.h> | |
38 #include <math.h> | |
39 #include <string.h> | |
40 | |
41 #include "platform/smartinclude.h" | |
42 #include "ui_skin.h" | |
43 #include "ui_manager.h" | |
44 #include "actions-equalizer.h" | |
45 #include "util.h" | |
46 #include "ui_main.h" | |
2678 | 47 #include "ui_playlist.h" |
2606 | 48 #include <audacious/plugin.h> |
49 | |
50 #include "images/audacious_eq.xpm" | |
51 | |
52 #include "ui_dock.h" | |
53 #include "ui_skinned_window.h" | |
54 #include "ui_skinned_button.h" | |
55 #include "ui_skinned_horizontal_slider.h" | |
56 #include "ui_skinned_equalizer_slider.h" | |
57 #include "ui_skinned_equalizer_graph.h" | |
58 #include "skins_cfg.h" | |
59 | |
60 enum PresetViewCols { | |
61 PRESET_VIEW_COL_NAME, | |
62 PRESET_VIEW_N_COLS | |
63 }; | |
64 | |
65 struct _EqualizerPreset { | |
66 gchar *name; | |
67 gfloat preamp, bands[10]; | |
68 }; | |
69 | |
70 typedef struct _EqualizerPreset EqualizerPreset; | |
71 | |
72 | |
73 GtkWidget *equalizerwin; | |
74 GtkWidget *equalizerwin_graph; | |
75 | |
76 static GtkWidget *equalizerwin_load_window = NULL; | |
77 static GtkWidget *equalizerwin_load_auto_window = NULL; | |
78 static GtkWidget *equalizerwin_save_window = NULL; | |
79 static GtkWidget *equalizerwin_save_entry = NULL; | |
80 static GtkWidget *equalizerwin_save_auto_window = NULL; | |
81 static GtkWidget *equalizerwin_save_auto_entry = NULL; | |
82 static GtkWidget *equalizerwin_delete_window = NULL; | |
83 static GtkWidget *equalizerwin_delete_auto_window = NULL; | |
84 | |
85 static GtkWidget *equalizerwin_on, *equalizerwin_auto; | |
86 | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
87 static GtkWidget *equalizerwin_close, *equalizerwin_shade; |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
88 static GtkWidget *equalizerwin_shaded_close, *equalizerwin_shaded_shade; |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
89 static GtkWidget *equalizerwin_presets; |
2606 | 90 static GtkWidget *equalizerwin_preamp,*equalizerwin_bands[10]; |
91 static GtkWidget *equalizerwin_volume, *equalizerwin_balance; | |
92 | |
93 static GList *equalizer_presets = NULL, *equalizer_auto_presets = NULL; | |
94 | |
95 EqualizerPreset * | |
96 equalizer_preset_new(const gchar * name) | |
97 { | |
98 EqualizerPreset *preset = g_new0(EqualizerPreset, 1); | |
99 preset->name = g_strdup(name); | |
100 return preset; | |
101 } | |
102 | |
103 void | |
104 equalizer_preset_free(EqualizerPreset * preset) | |
105 { | |
106 if (!preset) | |
107 return; | |
108 | |
109 g_free(preset->name); | |
110 g_free(preset); | |
111 } | |
112 | |
113 void | |
114 equalizerwin_set_scaled(gboolean ds) | |
115 { | |
116 gint height; | |
117 | |
118 if (config.equalizer_shaded) | |
119 height = 14; | |
120 else | |
121 height = 116; | |
122 | |
123 if (config.scaled) { | |
124 dock_window_resize(GTK_WINDOW(equalizerwin), 275 * config.scale_factor, | |
125 height * config.scale_factor, 275 * config.scale_factor, height * config.scale_factor); | |
126 } else { | |
127 dock_window_resize(GTK_WINDOW(equalizerwin), 275, height, 275, height); | |
128 } | |
129 | |
130 GList *iter; | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
131 for (iter = GTK_FIXED (SKINNED_WINDOW(equalizerwin)->normal)->children; iter; iter = g_list_next (iter)) { |
2606 | 132 GtkFixedChild *child_data = (GtkFixedChild *) iter->data; |
133 GtkWidget *child = child_data->widget; | |
134 g_signal_emit_by_name(child, "toggle-scaled"); | |
135 } | |
136 gtk_widget_shape_combine_mask(equalizerwin, skin_get_mask(aud_active_skin, SKIN_MASK_EQ + config.equalizer_shaded), 0, 0); | |
137 } | |
138 | |
139 void | |
140 equalizerwin_set_shade_menu_cb(gboolean shaded) | |
141 { | |
142 config.equalizer_shaded = shaded; | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
143 ui_skinned_window_set_shade(equalizerwin, shaded); |
2606 | 144 |
145 if (shaded) { | |
146 dock_shade(get_dock_window_list(), GTK_WINDOW(equalizerwin), | |
147 14 * EQUALIZER_SCALE_FACTOR); | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
148 } else { |
2606 | 149 dock_shade(get_dock_window_list(), GTK_WINDOW(equalizerwin), |
150 116 * EQUALIZER_SCALE_FACTOR); | |
151 } | |
152 | |
153 gtk_widget_shape_combine_mask(equalizerwin, skin_get_mask(aud_active_skin, SKIN_MASK_EQ + config.equalizer_shaded), 0, 0); | |
154 } | |
155 | |
156 static void | |
157 equalizerwin_set_shade(gboolean shaded) | |
158 { | |
159 GtkAction *action = gtk_action_group_get_action( | |
160 toggleaction_group_others , "roll up equalizer" ); | |
161 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , shaded ); | |
162 } | |
163 | |
164 static void | |
165 equalizerwin_shade_toggle(void) | |
166 { | |
167 equalizerwin_set_shade(!config.equalizer_shaded); | |
168 } | |
169 | |
170 void | |
171 equalizerwin_eq_changed(void) | |
172 { | |
173 gint i; | |
174 | |
175 aud_cfg->equalizer_preamp = ui_skinned_equalizer_slider_get_position(equalizerwin_preamp); | |
176 for (i = 0; i < 10; i++) | |
177 aud_cfg->equalizer_bands[i] = ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]); | |
2641 | 178 |
179 aud_hook_call("equalizer changed", NULL); | |
2606 | 180 gtk_widget_queue_draw(equalizerwin_graph); |
181 } | |
182 | |
183 static void | |
184 equalizerwin_on_pushed(void) | |
185 { | |
186 aud_cfg->equalizer_active = UI_SKINNED_BUTTON(equalizerwin_on)->inside; | |
187 equalizerwin_eq_changed(); | |
188 } | |
189 | |
190 static void | |
191 equalizerwin_presets_pushed(void) | |
192 { | |
193 GdkModifierType modmask; | |
194 gint x, y; | |
195 | |
196 gdk_window_get_pointer(NULL, &x, &y, &modmask); | |
197 ui_manager_popup_menu_show(GTK_MENU(equalizerwin_presets_menu), x, y, 1, GDK_CURRENT_TIME); | |
198 } | |
199 | |
200 static void | |
201 equalizerwin_auto_pushed(void) | |
202 { | |
203 aud_cfg->equalizer_autoload = UI_SKINNED_BUTTON(equalizerwin_auto)->inside; | |
204 } | |
205 | |
206 gboolean | |
207 equalizerwin_press(GtkWidget * widget, GdkEventButton * event, | |
208 gpointer callback_data) | |
209 { | |
210 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS | |
211 && event->y < 14) { | |
212 equalizerwin_set_shade(!config.equalizer_shaded); | |
213 if (dock_is_moving(GTK_WINDOW(equalizerwin))) | |
214 dock_move_release(GTK_WINDOW(equalizerwin)); | |
215 return TRUE; | |
216 } | |
217 if (event->button == 3) { | |
218 /* | |
219 * Pop up the main menu a few pixels down to avoid | |
220 * anything to be selected initially. | |
221 */ | |
222 ui_manager_popup_menu_show(GTK_MENU(mainwin_general_menu), event->x_root, | |
223 event->y_root + 2, 3, event->time); | |
224 return TRUE; | |
225 } | |
226 | |
227 return FALSE; | |
228 } | |
229 | |
230 static gboolean | |
231 equalizerwin_keypress(GtkWidget * widget, | |
232 GdkEventKey * event, | |
233 gpointer data) | |
234 { | |
235 if (event->keyval == GDK_Tab && event->state & GDK_CONTROL_MASK) { | |
236 if (config.playlist_visible) | |
237 gtk_window_present(GTK_WINDOW(playlistwin)); | |
238 else if (config.player_visible) | |
239 gtk_window_present(GTK_WINDOW(mainwin)); | |
240 return TRUE; | |
241 } | |
242 if (!config.equalizer_shaded) { | |
243 gtk_widget_event(mainwin, (GdkEvent *) event); | |
244 return TRUE; | |
245 } | |
246 | |
247 switch (event->keyval) { | |
248 case GDK_Left: | |
249 case GDK_KP_Left: | |
250 mainwin_set_balance_diff(-4); | |
251 break; | |
252 case GDK_Right: | |
253 case GDK_KP_Right: | |
254 mainwin_set_balance_diff(4); | |
255 break; | |
256 default: | |
257 gtk_widget_event(mainwin, (GdkEvent *) event); | |
258 break; | |
259 } | |
260 | |
261 return FALSE; | |
262 } | |
263 | |
264 static void | |
265 equalizerwin_close_cb(void) | |
266 { | |
267 equalizerwin_show(FALSE); | |
268 } | |
269 | |
270 static gboolean | |
271 equalizerwin_delete(GtkWidget * widget, | |
272 gpointer data) | |
273 { | |
274 equalizerwin_show(FALSE); | |
275 return TRUE; | |
276 } | |
277 | |
278 static GList * | |
279 equalizerwin_read_presets(const gchar * basename) | |
280 { | |
281 #if 0 | |
282 gchar *filename, *name; | |
283 RcFile *rcfile; | |
284 GList *list = NULL; | |
285 gint i, p = 0; | |
286 EqualizerPreset *preset; | |
287 | |
288 /* START mod: add check for the default presets locate in system path ({prefix}/share/audacious) | |
289 by Massimo Cavalleri (submax) */ | |
290 | |
291 filename = g_build_filename(aud_paths[BMP_PATH_USER_DIR], basename, NULL); | |
292 | |
293 if ((rcfile = aud_rcfile_open(filename)) == NULL) { | |
294 g_free(filename); | |
295 // DATA_DIR = "{prefix}/share/audacious" ; example is "/usr/share/audacious" | |
296 filename = g_build_filename(DATA_DIR, basename, NULL); | |
297 if ((rcfile = aud_rcfile_open(filename)) == NULL) { | |
298 g_free(filename); | |
299 return NULL; | |
300 } | |
301 } | |
302 | |
303 // END mod | |
304 | |
305 g_free(filename); | |
306 | |
307 for (;;) { | |
308 gchar section[21]; | |
309 | |
310 g_snprintf(section, sizeof(section), "Preset%d", p++); | |
311 if (aud_rcfile_read_string(rcfile, "Presets", section, &name)) { | |
312 preset = g_new0(EqualizerPreset, 1); | |
313 preset->name = name; | |
314 aud_rcfile_read_float(rcfile, name, "Preamp", &preset->preamp); | |
315 for (i = 0; i < 10; i++) { | |
316 gchar band[7]; | |
317 g_snprintf(band, sizeof(band), "Band%d", i); | |
318 aud_rcfile_read_float(rcfile, name, band, &preset->bands[i]); | |
319 } | |
320 list = g_list_prepend(list, preset); | |
321 } | |
322 else | |
323 break; | |
324 } | |
325 list = g_list_reverse(list); | |
326 aud_rcfile_free(rcfile); | |
327 return list; | |
328 #endif | |
329 } | |
330 | |
331 gint | |
332 equalizerwin_volume_frame_cb(gint pos) | |
333 { | |
334 if (equalizerwin_volume) { | |
335 gint x; | |
336 if (pos < 32) | |
337 x = 1; | |
338 else if (pos < 63) | |
339 x = 4; | |
340 else | |
341 x = 7; | |
342 | |
343 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_volume)->knob_nx = x; | |
344 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_volume)->knob_px = x; | |
345 } | |
346 return 1; | |
347 } | |
348 | |
349 static void | |
350 equalizerwin_volume_motion_cb(GtkWidget *widget, gint pos) | |
351 { | |
352 gint v = (gint) rint(pos * 100 / 94.0); | |
353 mainwin_adjust_volume_motion(v); | |
354 mainwin_set_volume_slider(v); | |
355 } | |
356 | |
357 static void | |
358 equalizerwin_volume_release_cb(GtkWidget *widget, gint pos) | |
359 { | |
360 mainwin_adjust_volume_release(); | |
361 } | |
362 | |
363 static gint | |
364 equalizerwin_balance_frame_cb(gint pos) | |
365 { | |
366 if (equalizerwin_balance) { | |
367 gint x; | |
368 if (pos < 13) | |
369 x = 11; | |
370 else if (pos < 26) | |
371 x = 14; | |
372 else | |
373 x = 17; | |
374 | |
375 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_balance)->knob_nx = x; | |
376 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_balance)->knob_px = x; | |
377 } | |
378 | |
379 return 1; | |
380 } | |
381 | |
382 static void | |
383 equalizerwin_balance_motion_cb(GtkWidget *widget, gint pos) | |
384 { | |
385 gint b; | |
386 pos = MIN(pos, 38); /* The skin uses a even number of pixels | |
387 for the balance-slider *sigh* */ | |
388 b = (gint) rint((pos - 19) * 100 / 19.0); | |
389 mainwin_adjust_balance_motion(b); | |
390 mainwin_set_balance_slider(b); | |
391 } | |
392 | |
393 static void | |
394 equalizerwin_balance_release_cb(GtkWidget *widget, gint pos) | |
395 { | |
396 mainwin_adjust_balance_release(); | |
397 } | |
398 | |
399 void | |
400 equalizerwin_set_balance_slider(gint percent) | |
401 { | |
402 ui_skinned_horizontal_slider_set_position(equalizerwin_balance, | |
403 (gint) rint((percent * 19 / 100.0) + 19)); | |
404 } | |
405 | |
406 void | |
407 equalizerwin_set_volume_slider(gint percent) | |
408 { | |
409 ui_skinned_horizontal_slider_set_position(equalizerwin_volume, | |
410 (gint) rint(percent * 94 / 100.0)); | |
411 } | |
412 | |
413 static void | |
414 equalizerwin_create_widgets(void) | |
415 { | |
416 gint i; | |
417 | |
418 equalizerwin_on = ui_skinned_button_new(); | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
419 ui_skinned_toggle_button_setup(equalizerwin_on, SKINNED_WINDOW(equalizerwin)->normal, |
2606 | 420 14, 18, 25, 12, 10, 119, 128, 119, 69, 119, 187, 119, SKIN_EQMAIN); |
421 g_signal_connect(equalizerwin_on, "clicked", equalizerwin_on_pushed, NULL); | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
422 ui_skinned_button_set_inside(equalizerwin_on, aud_cfg->equalizer_active); |
2606 | 423 |
424 equalizerwin_auto = ui_skinned_button_new(); | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
425 ui_skinned_toggle_button_setup(equalizerwin_auto, SKINNED_WINDOW(equalizerwin)->normal, |
2606 | 426 39, 18, 33, 12, 35, 119, 153, 119, 94, 119, 212, 119, SKIN_EQMAIN); |
427 g_signal_connect(equalizerwin_auto, "clicked", equalizerwin_auto_pushed, NULL); | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
428 ui_skinned_button_set_inside(equalizerwin_auto, aud_cfg->equalizer_autoload); |
2606 | 429 |
430 equalizerwin_presets = ui_skinned_button_new(); | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
431 ui_skinned_push_button_setup(equalizerwin_presets, SKINNED_WINDOW(equalizerwin)->normal, |
2606 | 432 217, 18, 44, 12, 224, 164, 224, 176, SKIN_EQMAIN); |
433 g_signal_connect(equalizerwin_presets, "clicked", equalizerwin_presets_pushed, NULL ); | |
434 | |
435 equalizerwin_close = ui_skinned_button_new(); | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
436 ui_skinned_push_button_setup(equalizerwin_close, SKINNED_WINDOW(equalizerwin)->normal, |
2606 | 437 264, 3, 9, 9, 0, 116, 0, 125, SKIN_EQMAIN); |
438 g_signal_connect(equalizerwin_close, "clicked", equalizerwin_close_cb, NULL ); | |
439 | |
440 equalizerwin_shade = ui_skinned_button_new(); | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
441 ui_skinned_push_button_setup(equalizerwin_shade, SKINNED_WINDOW(equalizerwin)->normal, |
2606 | 442 254, 3, 9, 9, 254, 137, 1, 38, SKIN_EQMAIN); |
443 ui_skinned_button_set_skin_index2(equalizerwin_shade, SKIN_EQ_EX); | |
444 g_signal_connect(equalizerwin_shade, "clicked", equalizerwin_shade_toggle, NULL ); | |
445 | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
446 equalizerwin_shaded_close = ui_skinned_button_new(); |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
447 ui_skinned_push_button_setup(equalizerwin_shaded_close, SKINNED_WINDOW(equalizerwin)->shaded, |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
448 264, 3, 9, 9, 11, 38, 11, 47, SKIN_EQ_EX); |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
449 g_signal_connect(equalizerwin_shaded_close, "clicked", equalizerwin_close_cb, NULL ); |
2606 | 450 |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
451 equalizerwin_shaded_shade = ui_skinned_button_new(); |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
452 ui_skinned_push_button_setup(equalizerwin_shaded_shade, SKINNED_WINDOW(equalizerwin)->shaded, |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
453 254, 3, 9, 9, 254, 3, 1, 47, SKIN_EQ_EX); |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
454 g_signal_connect(equalizerwin_shaded_shade, "clicked", equalizerwin_shade_toggle, NULL ); |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
455 |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
456 equalizerwin_graph = ui_skinned_equalizer_graph_new(SKINNED_WINDOW(equalizerwin)->normal, 86, 17); |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
457 |
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
458 equalizerwin_preamp = ui_skinned_equalizer_slider_new(SKINNED_WINDOW(equalizerwin)->normal, 21, 38); |
2606 | 459 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, aud_cfg->equalizer_preamp); |
460 | |
461 for (i = 0; i < 10; i++) { | |
462 equalizerwin_bands[i] = | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
463 ui_skinned_equalizer_slider_new(SKINNED_WINDOW(equalizerwin)->normal, 78 + (i * 18), 38); |
2606 | 464 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], aud_cfg->equalizer_bands[i]); |
465 } | |
466 | |
467 equalizerwin_volume = | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
468 ui_skinned_horizontal_slider_new(SKINNED_WINDOW(equalizerwin)->shaded, |
2606 | 469 61, 4, 97, 8, 1, 30, 1, 30, 3, 7, 4, 61, 0, 94, |
470 equalizerwin_volume_frame_cb, SKIN_EQ_EX); | |
471 g_signal_connect(equalizerwin_volume, "motion", G_CALLBACK(equalizerwin_volume_motion_cb), NULL); | |
472 g_signal_connect(equalizerwin_volume, "release", G_CALLBACK(equalizerwin_volume_release_cb), NULL); | |
473 | |
474 | |
475 equalizerwin_balance = | |
2719
51fc44b99b58
use two GtkFixed in SkinnedWindow - normal and shaded
Tomasz Mon <desowin@gmail.com>
parents:
2678
diff
changeset
|
476 ui_skinned_horizontal_slider_new(SKINNED_WINDOW(equalizerwin)->shaded, |
2606 | 477 164, 4, 42, 8, 11, 30, 11, 30, 3, 7, 4, 164, 0, 39, |
478 equalizerwin_balance_frame_cb, SKIN_EQ_EX); | |
479 g_signal_connect(equalizerwin_balance, "motion", G_CALLBACK(equalizerwin_balance_motion_cb), NULL); | |
480 g_signal_connect(equalizerwin_balance, "release", G_CALLBACK(equalizerwin_balance_release_cb), NULL); | |
481 } | |
482 | |
483 | |
484 static void | |
485 equalizerwin_create_window(void) | |
486 { | |
487 GdkPixbuf *icon; | |
488 gint width, height; | |
489 | |
490 width = 275; | |
491 height = config.equalizer_shaded ? 14 : 116; | |
492 | |
493 equalizerwin = ui_skinned_window_new("equalizer"); | |
494 gtk_window_set_title(GTK_WINDOW(equalizerwin), _("Audacious Equalizer")); | |
495 gtk_window_set_role(GTK_WINDOW(equalizerwin), "equalizer"); | |
496 gtk_window_set_resizable(GTK_WINDOW(equalizerwin), FALSE); | |
497 | |
498 if (config.scaled && config.eq_scaled_linked) { | |
499 width *= config.scale_factor; | |
500 height *= config.scale_factor; | |
501 } | |
502 | |
503 gtk_widget_set_size_request(equalizerwin, width, height); | |
504 | |
505 /* this will hide only mainwin. it's annoying! yaz */ | |
506 gtk_window_set_transient_for(GTK_WINDOW(equalizerwin), | |
507 GTK_WINDOW(mainwin)); | |
508 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(equalizerwin), TRUE); | |
509 | |
510 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_eq_icon); | |
511 gtk_window_set_icon(GTK_WINDOW(equalizerwin), icon); | |
512 g_object_unref(icon); | |
513 | |
514 gtk_widget_set_app_paintable(equalizerwin, TRUE); | |
515 | |
516 if (config.equalizer_x != -1 && config.save_window_position) | |
517 gtk_window_move(GTK_WINDOW(equalizerwin), | |
518 config.equalizer_x, config.equalizer_y); | |
519 | |
520 g_signal_connect(equalizerwin, "delete_event", | |
521 G_CALLBACK(equalizerwin_delete), NULL); | |
522 g_signal_connect(equalizerwin, "button_press_event", | |
523 G_CALLBACK(equalizerwin_press), NULL); | |
524 g_signal_connect(equalizerwin, "key_press_event", | |
525 G_CALLBACK(equalizerwin_keypress), NULL); | |
526 } | |
527 | |
528 void | |
529 equalizerwin_create(void) | |
530 { | |
531 equalizer_presets = equalizerwin_read_presets("eq.preset"); | |
532 equalizer_auto_presets = equalizerwin_read_presets("eq.auto_preset"); | |
533 | |
534 equalizerwin_create_window(); | |
535 | |
536 gtk_window_add_accel_group( GTK_WINDOW(equalizerwin) , ui_manager_get_accel_group() ); | |
537 | |
538 equalizerwin_create_widgets(); | |
539 } | |
540 | |
541 | |
542 void | |
543 equalizerwin_show(gboolean show) | |
544 { | |
545 GtkAction *action = gtk_action_group_get_action( | |
546 toggleaction_group_others , "show equalizer" ); | |
547 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , show ); | |
548 | |
549 if (show) | |
550 equalizerwin_real_show(); | |
551 else | |
552 equalizerwin_real_hide(); | |
553 } | |
554 | |
555 void | |
556 equalizerwin_real_show(void) | |
557 { | |
558 gtk_window_move(GTK_WINDOW(equalizerwin), config.equalizer_x, config.equalizer_y); | |
559 if (config.scaled && config.eq_scaled_linked) | |
560 gtk_widget_set_size_request(equalizerwin, 275 * config.scale_factor, | |
561 ((config.equalizer_shaded ? 14 : 116) * config.scale_factor)); | |
562 else | |
563 gtk_widget_set_size_request(equalizerwin, 275, | |
564 (config.equalizer_shaded ? 14 : 116)); | |
565 config.equalizer_visible = TRUE; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
566 ui_skinned_button_set_inside(mainwin_eq, TRUE); |
2606 | 567 gtk_widget_show_all(equalizerwin); |
568 | |
569 gtk_window_present(GTK_WINDOW(equalizerwin)); | |
570 } | |
571 | |
572 void | |
573 equalizerwin_real_hide(void) | |
574 { | |
575 /* | |
576 * This function should only be called from the | |
577 * main menu signal handler | |
578 */ | |
579 gtk_widget_hide(equalizerwin); | |
580 config.equalizer_visible = FALSE; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
581 ui_skinned_button_set_inside(mainwin_eq, FALSE); |
2606 | 582 gtk_widget_queue_draw(mainwin_eq); |
583 } | |
584 | |
585 static EqualizerPreset * | |
586 equalizerwin_find_preset(GList * list, const gchar * name) | |
587 { | |
588 GList *node = list; | |
589 EqualizerPreset *preset; | |
590 | |
591 while (node) { | |
592 preset = node->data; | |
593 if (!strcasecmp(preset->name, name)) | |
594 return preset; | |
595 node = g_list_next(node); | |
596 } | |
597 return NULL; | |
598 } | |
599 | |
600 static void | |
601 equalizerwin_write_preset_file(GList * list, const gchar * basename) | |
602 { | |
603 #if 0 | |
604 gchar *filename, *tmp; | |
605 gint i, p; | |
606 EqualizerPreset *preset; | |
607 RcFile *rcfile; | |
608 GList *node; | |
609 | |
610 rcfile = aud_rcfile_new(); | |
611 p = 0; | |
612 for (node = list; node; node = g_list_next(node)) { | |
613 preset = node->data; | |
614 tmp = g_strdup_printf("Preset%d", p++); | |
615 aud_rcfile_write_string(rcfile, "Presets", tmp, preset->name); | |
616 g_free(tmp); | |
617 aud_rcfile_write_float(rcfile, preset->name, "Preamp", | |
618 preset->preamp); | |
619 for (i = 0; i < 10; i++) { | |
620 tmp = g_strdup_printf("Band%d\n", i); | |
621 aud_rcfile_write_float(rcfile, preset->name, tmp, | |
622 preset->bands[i]); | |
623 g_free(tmp); | |
624 } | |
625 } | |
626 | |
627 filename = g_build_filename(aud_paths[BMP_PATH_USER_DIR], basename, NULL); | |
628 aud_rcfile_write(rcfile, filename); | |
629 aud_rcfile_free(rcfile); | |
630 g_free(filename); | |
631 #endif | |
632 } | |
633 | |
634 static gboolean | |
635 equalizerwin_load_preset(GList * list, const gchar * name) | |
636 { | |
637 EqualizerPreset *preset; | |
638 gint i; | |
639 | |
640 if ((preset = equalizerwin_find_preset(list, name)) != NULL) { | |
641 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, preset->preamp); | |
642 for (i = 0; i < 10; i++) | |
643 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], preset->bands[i]); | |
644 equalizerwin_eq_changed(); | |
645 return TRUE; | |
646 } | |
647 return FALSE; | |
648 } | |
649 | |
650 static GList * | |
651 equalizerwin_save_preset(GList * list, const gchar * name, | |
652 const gchar * filename) | |
653 { | |
654 gint i; | |
655 EqualizerPreset *preset; | |
656 | |
657 if (!(preset = equalizerwin_find_preset(list, name))) { | |
658 preset = g_new0(EqualizerPreset, 1); | |
659 preset->name = g_strdup(name); | |
660 list = g_list_append(list, preset); | |
661 } | |
662 | |
663 preset->preamp = ui_skinned_equalizer_slider_get_position(equalizerwin_preamp); | |
664 for (i = 0; i < 10; i++) | |
665 preset->bands[i] = ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]); | |
666 | |
667 equalizerwin_write_preset_file(list, filename); | |
668 | |
669 return list; | |
670 } | |
671 | |
672 static GList * | |
673 equalizerwin_delete_preset(GList * list, gchar * name, gchar * filename) | |
674 { | |
675 EqualizerPreset *preset; | |
676 GList *node; | |
677 | |
678 if (!(preset = equalizerwin_find_preset(list, name))) | |
679 return list; | |
680 | |
681 if (!(node = g_list_find(list, preset))) | |
682 return list; | |
683 | |
684 list = g_list_remove_link(list, node); | |
685 equalizer_preset_free(preset); | |
686 g_list_free_1(node); | |
687 | |
688 equalizerwin_write_preset_file(list, filename); | |
689 | |
690 return list; | |
691 } | |
692 | |
693 static void | |
694 equalizerwin_delete_selected_presets(GtkTreeView *view, gchar *filename) | |
695 { | |
696 gchar *text; | |
697 | |
698 GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
699 GtkTreeModel *model = gtk_tree_view_get_model(view); | |
700 | |
701 /* | |
702 * first we are making a list of the selected rows, then we convert this | |
703 * list into a list of GtkTreeRowReferences, so that when you delete an | |
704 * item you can still access the other items | |
705 * finally we iterate through all GtkTreeRowReferences, convert them to | |
706 * GtkTreeIters and delete those one after the other | |
707 */ | |
708 | |
709 GList *list = gtk_tree_selection_get_selected_rows(selection, &model); | |
710 GList *rrefs = NULL; | |
711 GList *litr; | |
712 | |
713 for (litr = list; litr; litr = litr->next) | |
714 { | |
715 GtkTreePath *path = litr->data; | |
716 rrefs = g_list_append(rrefs, gtk_tree_row_reference_new(model, path)); | |
717 } | |
718 | |
719 for (litr = rrefs; litr; litr = litr->next) | |
720 { | |
721 GtkTreeRowReference *ref = litr->data; | |
722 GtkTreePath *path = gtk_tree_row_reference_get_path(ref); | |
723 GtkTreeIter iter; | |
724 gtk_tree_model_get_iter(model, &iter, path); | |
725 | |
726 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
727 | |
728 if (!strcmp(filename, "eq.preset")) | |
729 equalizer_presets = equalizerwin_delete_preset(equalizer_presets, text, filename); | |
730 else if (!strcmp(filename, "eq.auto_preset")) | |
731 equalizer_auto_presets = equalizerwin_delete_preset(equalizer_auto_presets, text, filename); | |
732 | |
733 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
734 } | |
735 } | |
736 | |
737 static GList * | |
738 import_winamp_eqf(VFSFile * file) | |
739 { | |
740 #if 0 | |
741 gchar header[31]; | |
742 gchar bands[11]; | |
743 gint i = 0; | |
744 EqualizerPreset *preset = NULL; | |
745 GList *list = NULL; | |
746 GtkWidget *dialog; | |
747 gchar *realfn; | |
748 gchar preset_name[0xb4]; | |
749 | |
750 vfs_fread(header, 1, 31, file); | |
751 if (strncmp(header, "Winamp EQ library file v1.1", 27)) goto error; | |
752 | |
753 AUDDBG("The EQF header is OK\n"); | |
754 | |
755 if (vfs_fseek(file, 0x1f, SEEK_SET) == -1) goto error; | |
756 | |
757 while (vfs_fread(preset_name, 1, 0xb4, file) == 0xb4) { | |
758 AUDDBG("The preset name is '%s'\n", preset_name); | |
759 vfs_fseek(file, 0x4d, SEEK_CUR); /* unknown crap --asphyx */ | |
760 if (vfs_fread(bands, 1, 11, file) != 11) break; | |
761 | |
762 preset = equalizer_preset_new(preset_name); | |
763 /*this was divided by 63, but shouldn't it be 64? --majeru*/ | |
764 preset->preamp = EQUALIZER_MAX_GAIN - ((bands[10] * EQUALIZER_MAX_GAIN * 2) / 64.0); | |
765 | |
766 for (i = 0; i < 10; i++) | |
767 preset->bands[i] = EQUALIZER_MAX_GAIN - ((bands[i] * EQUALIZER_MAX_GAIN * 2) / 64.0); | |
768 | |
769 list = g_list_prepend(list, preset); | |
770 } | |
771 | |
772 list = g_list_reverse(list); | |
773 if (list == NULL) goto error; | |
774 | |
775 return list; | |
776 | |
777 error: | |
778 realfn = g_filename_from_uri(file->uri, NULL, NULL); | |
779 dialog = gtk_message_dialog_new (GTK_WINDOW(mainwin), | |
780 GTK_DIALOG_DESTROY_WITH_PARENT, | |
781 GTK_MESSAGE_ERROR, | |
782 GTK_BUTTONS_CLOSE, | |
783 _("Error importing Winamp EQF file '%s'"), | |
784 realfn); | |
785 gtk_dialog_run (GTK_DIALOG (dialog)); | |
786 gtk_widget_destroy (dialog); | |
787 g_free(realfn); | |
788 return NULL; | |
789 #endif | |
790 } | |
791 | |
792 static void | |
793 free_cb (gpointer data, gpointer user_data) | |
794 { | |
795 equalizer_preset_free((EqualizerPreset*)data); | |
796 } | |
797 | |
798 static void | |
799 equalizerwin_read_winamp_eqf(VFSFile * file) | |
800 { | |
801 GList *presets; | |
802 gint i; | |
803 | |
804 if ((presets = import_winamp_eqf(file)) == NULL) | |
805 return; | |
806 | |
807 /* just get the first preset --asphyx */ | |
808 EqualizerPreset *preset = (EqualizerPreset*)presets->data; | |
809 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, | |
810 preset->preamp); | |
811 | |
812 for (i = 0; i < 10; i++) | |
813 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], | |
814 preset->bands[i]); | |
815 | |
816 g_list_foreach(presets, free_cb, NULL); | |
817 g_list_free(presets); | |
818 | |
819 equalizerwin_eq_changed(); | |
820 } | |
821 #if 0 | |
822 static void | |
823 equalizerwin_read_aud_preset(RcFile * rcfile) | |
824 { | |
825 gfloat val; | |
826 gint i; | |
827 | |
828 if (aud_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val)) | |
829 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, val); | |
830 for (i = 0; i < 10; i++) { | |
831 gchar tmp[7]; | |
832 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
833 if (aud_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val)) | |
834 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], val); | |
835 } | |
836 equalizerwin_eq_changed(); | |
837 } | |
838 #endif | |
839 | |
840 static void | |
841 equalizerwin_save_ok(GtkWidget * widget, gpointer data) | |
842 { | |
843 const gchar *text; | |
844 | |
845 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_entry)); | |
846 if (strlen(text) != 0) | |
847 equalizer_presets = | |
848 equalizerwin_save_preset(equalizer_presets, text, "eq.preset"); | |
849 gtk_widget_destroy(equalizerwin_save_window); | |
850 } | |
851 | |
852 static void | |
853 equalizerwin_save_select(GtkTreeView *treeview, GtkTreePath *path, | |
854 GtkTreeViewColumn *col, gpointer data) | |
855 { | |
856 gchar *text; | |
857 | |
858 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); | |
859 GtkTreeModel *model; | |
860 GtkTreeIter iter; | |
861 | |
862 if (selection) | |
863 { | |
864 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
865 { | |
866 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
867 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_entry), text); | |
868 equalizerwin_save_ok(NULL, NULL); | |
869 | |
870 g_free(text); | |
871 } | |
872 } | |
873 } | |
874 | |
875 static void | |
876 equalizerwin_load_ok(GtkWidget *widget, gpointer data) | |
877 { | |
878 gchar *text; | |
879 | |
880 GtkTreeView* view = GTK_TREE_VIEW(data); | |
881 GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
882 GtkTreeModel *model; | |
883 GtkTreeIter iter; | |
884 | |
885 if (selection) | |
886 { | |
887 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
888 { | |
889 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
890 equalizerwin_load_preset(equalizer_presets, text); | |
891 | |
892 g_free(text); | |
893 } | |
894 } | |
895 gtk_widget_destroy(equalizerwin_load_window); | |
896 } | |
897 | |
898 static void | |
899 equalizerwin_load_select(GtkTreeView *treeview, GtkTreePath *path, | |
900 GtkTreeViewColumn *col, gpointer data) | |
901 { | |
902 equalizerwin_load_ok(NULL, treeview); | |
903 } | |
904 | |
905 static void | |
906 equalizerwin_delete_delete(GtkWidget *widget, gpointer data) | |
907 { | |
908 equalizerwin_delete_selected_presets(GTK_TREE_VIEW(data), "eq.preset"); | |
909 } | |
910 | |
911 static void | |
912 equalizerwin_save_auto_ok(GtkWidget *widget, gpointer data) | |
913 { | |
914 const gchar *text; | |
915 | |
916 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_auto_entry)); | |
917 if (strlen(text) != 0) | |
918 equalizer_auto_presets = | |
919 equalizerwin_save_preset(equalizer_auto_presets, text, | |
920 "eq.auto_preset"); | |
921 gtk_widget_destroy(equalizerwin_save_auto_window); | |
922 } | |
923 | |
924 static void | |
925 equalizerwin_save_auto_select(GtkTreeView *treeview, GtkTreePath *path, | |
926 GtkTreeViewColumn *col, gpointer data) | |
927 { | |
928 gchar *text; | |
929 | |
930 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); | |
931 GtkTreeModel *model; | |
932 GtkTreeIter iter; | |
933 | |
934 if (selection) | |
935 { | |
936 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
937 { | |
938 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
939 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), text); | |
940 equalizerwin_save_auto_ok(NULL, NULL); | |
941 | |
942 g_free(text); | |
943 } | |
944 } | |
945 } | |
946 | |
947 static void | |
948 equalizerwin_load_auto_ok(GtkWidget *widget, gpointer data) | |
949 { | |
950 gchar *text; | |
951 | |
952 GtkTreeView *view = GTK_TREE_VIEW(data); | |
953 GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
954 GtkTreeModel *model; | |
955 GtkTreeIter iter; | |
956 | |
957 if (selection) | |
958 { | |
959 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
960 { | |
961 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
962 equalizerwin_load_preset(equalizer_auto_presets, text); | |
963 | |
964 g_free(text); | |
965 } | |
966 } | |
967 gtk_widget_destroy(equalizerwin_load_auto_window); | |
968 } | |
969 | |
970 static void | |
971 equalizerwin_load_auto_select(GtkTreeView *treeview, GtkTreePath *path, | |
972 GtkTreeViewColumn *col, gpointer data) | |
973 { | |
974 equalizerwin_load_auto_ok(NULL, treeview); | |
975 } | |
976 | |
977 static void | |
978 equalizerwin_delete_auto_delete(GtkWidget *widget, gpointer data) | |
979 { | |
980 equalizerwin_delete_selected_presets(GTK_TREE_VIEW(data), "eq.auto_preset"); | |
981 } | |
982 | |
983 | |
984 static void | |
985 load_preset_file(const gchar *filename) | |
986 { | |
987 #if 0 | |
988 RcFile *rcfile; | |
989 | |
990 if ((rcfile = aud_rcfile_open(filename)) != NULL) { | |
991 equalizerwin_read_aud_preset(rcfile); | |
992 aud_rcfile_free(rcfile); | |
993 } | |
994 #endif | |
995 } | |
996 | |
997 static VFSFile * | |
998 open_vfs_file(const gchar *filename, const gchar *mode) | |
999 { | |
1000 VFSFile *file; | |
1001 GtkWidget *dialog; | |
1002 | |
1003 if (!(file = vfs_fopen(filename, mode))) { | |
1004 dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin), | |
1005 GTK_DIALOG_DESTROY_WITH_PARENT, | |
1006 GTK_MESSAGE_ERROR, | |
1007 GTK_BUTTONS_CLOSE, | |
1008 "Error loading file '%s'", | |
1009 filename); | |
1010 gtk_dialog_run (GTK_DIALOG (dialog)); | |
1011 gtk_widget_destroy (dialog); | |
1012 } | |
1013 | |
1014 return file; | |
1015 } | |
1016 | |
1017 static void | |
1018 load_winamp_file(const gchar * filename) | |
1019 { | |
1020 #if 0 | |
1021 VFSFile *file; | |
1022 | |
1023 if (!(file = open_vfs_file(filename, "rb"))) | |
1024 return; | |
1025 | |
1026 equalizerwin_read_winamp_eqf(file); | |
1027 vfs_fclose(file); | |
1028 #endif | |
1029 } | |
1030 | |
1031 static void | |
1032 import_winamp_file(const gchar * filename) | |
1033 { | |
1034 #if 0 | |
1035 VFSFile *file; | |
1036 GList *list; | |
1037 | |
1038 if (!(file = open_vfs_file(filename, "rb")) || | |
1039 !(list = import_winamp_eqf(file))) | |
1040 return; | |
1041 | |
1042 equalizer_presets = g_list_concat(equalizer_presets, list); | |
1043 equalizerwin_write_preset_file(equalizer_presets, "eq.preset"); | |
1044 | |
1045 vfs_fclose(file); | |
1046 #endif | |
1047 } | |
1048 | |
1049 static void | |
1050 save_preset_file(const gchar * filename) | |
1051 { | |
1052 #if 0 | |
1053 RcFile *rcfile; | |
1054 gint i; | |
1055 | |
1056 rcfile = aud_rcfile_new(); | |
1057 aud_rcfile_write_float(rcfile, "Equalizer preset", "Preamp", | |
1058 ui_skinned_equalizer_slider_get_position(equalizerwin_preamp)); | |
1059 | |
1060 for (i = 0; i < 10; i++) { | |
1061 gchar tmp[7]; | |
1062 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1063 aud_rcfile_write_float(rcfile, "Equalizer preset", tmp, | |
1064 ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i])); | |
1065 } | |
1066 | |
1067 aud_rcfile_write(rcfile, filename); | |
1068 aud_rcfile_free(rcfile); | |
1069 #endif | |
1070 } | |
1071 | |
1072 static void | |
1073 save_winamp_file(const gchar * filename) | |
1074 { | |
1075 #if 0 | |
1076 VFSFile *file; | |
1077 | |
1078 gchar name[257]; | |
1079 gint i; | |
1080 guchar bands[11]; | |
1081 | |
1082 if (!(file = open_vfs_file(filename, "wb"))) | |
1083 return; | |
1084 | |
1085 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file); | |
1086 | |
1087 memset(name, 0, 257); | |
1088 g_strlcpy(name, "Entry1", 257); | |
1089 vfs_fwrite(name, 1, 257, file); | |
1090 | |
1091 for (i = 0; i < 10; i++) | |
1092 bands[i] = 63 - (((ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]) + EQUALIZER_MAX_GAIN) * 63) / EQUALIZER_MAX_GAIN / 2); | |
1093 bands[10] = 63 - (((ui_skinned_equalizer_slider_get_position(equalizerwin_preamp) + EQUALIZER_MAX_GAIN) * 63) / EQUALIZER_MAX_GAIN / 2); | |
1094 vfs_fwrite(bands, 1, 11, file); | |
1095 | |
1096 vfs_fclose(file); | |
1097 #endif | |
1098 } | |
1099 | |
1100 static GtkWidget * | |
1101 equalizerwin_create_list_window(GList *preset_list, | |
1102 const gchar *title, | |
1103 GtkWidget **window, | |
1104 GtkSelectionMode sel_mode, | |
1105 GtkWidget **entry, | |
1106 const gchar *action_name, | |
1107 GCallback action_func, | |
1108 GCallback select_row_func) | |
1109 { | |
1110 GtkWidget *vbox, *scrolled_window, *bbox, *view; | |
1111 GtkWidget *button_cancel, *button_action; | |
1112 GList *node; | |
1113 | |
1114 GtkListStore *store; | |
1115 GtkTreeIter iter; | |
1116 GtkTreeModel *model; | |
1117 GtkCellRenderer *renderer; | |
1118 GtkTreeSelection *selection; | |
1119 GtkTreeSortable *sortable; | |
1120 | |
1121 | |
1122 | |
1123 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1124 gtk_window_set_title(GTK_WINDOW(*window), title); | |
1125 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
1126 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); | |
1127 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); | |
1128 gtk_container_set_border_width(GTK_CONTAINER(*window), 10); | |
1129 gtk_window_set_transient_for(GTK_WINDOW(*window), | |
1130 GTK_WINDOW(equalizerwin)); | |
1131 g_signal_connect(*window, "destroy", | |
1132 G_CALLBACK(gtk_widget_destroyed), window); | |
1133 | |
1134 vbox = gtk_vbox_new(FALSE, 10); | |
1135 gtk_container_add(GTK_CONTAINER(*window), vbox); | |
1136 | |
1137 scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
1138 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | |
1139 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1140 | |
1141 | |
1142 /* fill the store with the names of all available presets */ | |
1143 store = gtk_list_store_new(1, G_TYPE_STRING); | |
1144 for (node = preset_list; node; node = g_list_next(node)) | |
1145 { | |
1146 gtk_list_store_append(store, &iter); | |
1147 gtk_list_store_set(store, &iter, | |
1148 0, ((EqualizerPreset*)node->data)->name, | |
1149 -1); | |
1150 } | |
1151 model = GTK_TREE_MODEL(store); | |
1152 | |
1153 | |
1154 sortable = GTK_TREE_SORTABLE(store); | |
1155 gtk_tree_sortable_set_sort_column_id(sortable, 0, GTK_SORT_ASCENDING); | |
1156 | |
1157 | |
1158 view = gtk_tree_view_new(); | |
1159 renderer = gtk_cell_renderer_text_new(); | |
1160 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, | |
1161 _("Presets"), renderer, | |
1162 "text", 0, NULL); | |
1163 gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); | |
1164 g_object_unref(model); | |
1165 | |
1166 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
1167 gtk_tree_selection_set_mode(selection, sel_mode); | |
1168 | |
1169 | |
1170 | |
1171 | |
1172 gtk_container_add(GTK_CONTAINER(scrolled_window), view); | |
1173 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); | |
1174 | |
1175 if (entry) { | |
1176 *entry = gtk_entry_new(); | |
1177 g_signal_connect(*entry, "activate", action_func, NULL); | |
1178 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); | |
1179 } | |
1180 | |
1181 bbox = gtk_hbutton_box_new(); | |
1182 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1183 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1184 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1185 | |
1186 button_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1187 g_signal_connect_swapped(button_cancel, "clicked", | |
1188 G_CALLBACK(gtk_widget_destroy), | |
1189 GTK_OBJECT(*window)); | |
1190 gtk_box_pack_start(GTK_BOX(bbox), button_cancel, TRUE, TRUE, 0); | |
1191 | |
1192 button_action = gtk_button_new_from_stock(action_name); | |
1193 g_signal_connect(button_action, "clicked", G_CALLBACK(action_func), view); | |
1194 GTK_WIDGET_SET_FLAGS(button_action, GTK_CAN_DEFAULT); | |
1195 | |
1196 if (select_row_func) | |
1197 g_signal_connect(view, "row-activated", G_CALLBACK(select_row_func), NULL); | |
1198 | |
1199 | |
1200 gtk_box_pack_start(GTK_BOX(bbox), button_action, TRUE, TRUE, 0); | |
1201 | |
1202 gtk_widget_grab_default(button_action); | |
1203 | |
1204 | |
1205 gtk_widget_show_all(*window); | |
1206 | |
1207 return *window; | |
1208 } | |
1209 | |
1210 void | |
1211 equalizerwin_load_auto_preset(const gchar * filename) | |
1212 { | |
1213 #if 0 | |
1214 gchar *presetfilename, *directory; | |
1215 RcFile *rcfile; | |
1216 | |
1217 g_return_if_fail(filename != NULL); | |
1218 | |
1219 if (!aud_cfg->equalizer_autoload) | |
1220 return; | |
1221 | |
1222 presetfilename = g_strconcat(filename, ".", aud_cfg->eqpreset_extension, NULL); | |
1223 | |
1224 /* First try to find a per file preset file */ | |
1225 if (strlen(aud_cfg->eqpreset_extension) > 0 && | |
1226 (rcfile = aud_rcfile_open(presetfilename)) != NULL) { | |
1227 g_free(presetfilename); | |
1228 equalizerwin_read_aud_preset(rcfile); | |
1229 aud_rcfile_free(rcfile); | |
1230 return; | |
1231 } | |
1232 | |
1233 g_free(presetfilename); | |
1234 | |
1235 directory = g_path_get_dirname(filename); | |
1236 presetfilename = g_build_filename(directory, aud_cfg->eqpreset_default_file, | |
1237 NULL); | |
1238 g_free(directory); | |
1239 | |
1240 /* Try to find a per directory preset file */ | |
1241 if (strlen(aud_cfg->eqpreset_default_file) > 0 && | |
1242 (rcfile = aud_rcfile_open(presetfilename)) != NULL) { | |
1243 equalizerwin_read_aud_preset(rcfile); | |
1244 aud_rcfile_free(rcfile); | |
1245 } | |
1246 else if (!equalizerwin_load_preset | |
1247 (equalizer_auto_presets, g_basename(filename))) { | |
1248 /* Fall back to the oldstyle auto presets */ | |
1249 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1250 } | |
1251 | |
1252 g_free(presetfilename); | |
1253 #endif | |
1254 } | |
1255 | |
1256 void | |
1257 equalizerwin_set_preamp(gfloat preamp) | |
1258 { | |
1259 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, preamp); | |
1260 equalizerwin_eq_changed(); | |
1261 } | |
1262 | |
1263 void | |
1264 equalizerwin_set_band(gint band, gfloat value) | |
1265 { | |
1266 g_return_if_fail(band >= 0 && band < 10); | |
1267 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[band], value); | |
1268 } | |
1269 | |
1270 gfloat | |
1271 equalizerwin_get_preamp(void) | |
1272 { | |
1273 return ui_skinned_equalizer_slider_get_position(equalizerwin_preamp); | |
1274 } | |
1275 | |
1276 gfloat | |
1277 equalizerwin_get_band(gint band) | |
1278 { | |
1279 g_return_val_if_fail(band >= 0 && band < 10, 0.0); | |
1280 return ui_skinned_equalizer_slider_get_position(equalizerwin_bands[band]); | |
1281 } | |
1282 | |
1283 void | |
1284 action_equ_load_preset(void) | |
1285 { | |
1286 if (equalizerwin_load_window) { | |
1287 gtk_window_present(GTK_WINDOW(equalizerwin_load_window)); | |
1288 return; | |
1289 } | |
1290 | |
1291 equalizerwin_create_list_window(equalizer_presets, | |
1292 Q_("Load preset"), | |
1293 &equalizerwin_load_window, | |
1294 GTK_SELECTION_SINGLE, NULL, | |
1295 GTK_STOCK_OK, | |
1296 G_CALLBACK(equalizerwin_load_ok), | |
1297 G_CALLBACK(equalizerwin_load_select)); | |
1298 } | |
1299 | |
1300 void | |
1301 action_equ_load_auto_preset(void) | |
1302 { | |
1303 if (equalizerwin_load_auto_window) { | |
1304 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window)); | |
1305 return; | |
1306 } | |
1307 | |
1308 equalizerwin_create_list_window(equalizer_auto_presets, | |
1309 Q_("Load auto-preset"), | |
1310 &equalizerwin_load_auto_window, | |
1311 GTK_SELECTION_SINGLE, NULL, | |
1312 GTK_STOCK_OK, | |
1313 G_CALLBACK(equalizerwin_load_auto_ok), | |
1314 G_CALLBACK(equalizerwin_load_auto_select)); | |
1315 } | |
1316 | |
1317 void | |
1318 action_equ_load_default_preset(void) | |
1319 { | |
1320 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1321 } | |
1322 | |
1323 void | |
1324 action_equ_zero_preset(void) | |
1325 { | |
1326 gint i; | |
1327 | |
1328 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, 0); | |
1329 for (i = 0; i < 10; i++) | |
1330 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], 0); | |
1331 | |
1332 equalizerwin_eq_changed(); | |
1333 } | |
1334 | |
1335 void | |
1336 action_equ_load_preset_file(void) | |
1337 { | |
1338 GtkWidget *dialog; | |
1339 gchar *file_uri; | |
1340 | |
1341 dialog = make_filebrowser(Q_("Load equalizer preset"), FALSE); | |
1342 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1343 { | |
1344 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1345 load_preset_file(file_uri); | |
1346 g_free(file_uri); | |
1347 } | |
1348 gtk_widget_destroy(dialog); | |
1349 } | |
1350 | |
1351 void | |
1352 action_equ_load_preset_eqf(void) | |
1353 { | |
1354 GtkWidget *dialog; | |
1355 gchar *file_uri; | |
1356 | |
1357 dialog = make_filebrowser(Q_("Load equalizer preset"), FALSE); | |
1358 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1359 { | |
1360 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1361 load_winamp_file(file_uri); | |
1362 g_free(file_uri); | |
1363 } | |
1364 gtk_widget_destroy(dialog); | |
1365 } | |
1366 | |
1367 void | |
1368 action_equ_import_winamp_presets(void) | |
1369 { | |
1370 GtkWidget *dialog; | |
1371 gchar *file_uri; | |
1372 | |
1373 dialog = make_filebrowser(Q_("Load equalizer preset"), FALSE); | |
1374 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1375 { | |
1376 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1377 import_winamp_file(file_uri); | |
1378 g_free(file_uri); | |
1379 } | |
1380 gtk_widget_destroy(dialog); | |
1381 } | |
1382 | |
1383 void | |
1384 action_equ_save_preset(void) | |
1385 { | |
1386 if (equalizerwin_save_window) { | |
1387 gtk_window_present(GTK_WINDOW(equalizerwin_save_window)); | |
1388 return; | |
1389 } | |
1390 | |
1391 equalizerwin_create_list_window(equalizer_presets, | |
1392 Q_("Save preset"), | |
1393 &equalizerwin_save_window, | |
1394 GTK_SELECTION_SINGLE, | |
1395 &equalizerwin_save_entry, | |
1396 GTK_STOCK_OK, | |
1397 G_CALLBACK(equalizerwin_save_ok), | |
1398 G_CALLBACK(equalizerwin_save_select)); | |
1399 } | |
1400 | |
1401 void | |
1402 action_equ_save_auto_preset(void) | |
1403 { | |
1404 gchar *name; | |
1405 Playlist *playlist = aud_playlist_get_active(); | |
1406 | |
1407 if (equalizerwin_save_auto_window) | |
1408 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window)); | |
1409 else | |
1410 equalizerwin_create_list_window(equalizer_auto_presets, | |
1411 Q_("Save auto-preset"), | |
1412 &equalizerwin_save_auto_window, | |
1413 GTK_SELECTION_SINGLE, | |
1414 &equalizerwin_save_auto_entry, | |
1415 GTK_STOCK_OK, | |
1416 G_CALLBACK(equalizerwin_save_auto_ok), | |
1417 G_CALLBACK(equalizerwin_save_auto_select)); | |
1418 | |
1419 name = aud_playlist_get_filename(playlist, aud_playlist_get_position(playlist)); | |
1420 if (name) { | |
1421 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), | |
1422 g_basename(name)); | |
1423 g_free(name); | |
1424 } | |
1425 } | |
1426 | |
1427 void | |
1428 action_equ_save_default_preset(void) | |
1429 { | |
1430 equalizer_presets = | |
1431 equalizerwin_save_preset(equalizer_presets, Q_("Default"), "eq.preset"); | |
1432 } | |
1433 | |
1434 void | |
1435 action_equ_save_preset_file(void) | |
1436 { | |
1437 GtkWidget *dialog; | |
1438 gchar *file_uri; | |
1439 gchar *songname; | |
1440 Playlist *playlist = aud_playlist_get_active(); | |
1441 | |
1442 dialog = make_filebrowser(Q_("Save equalizer preset"), TRUE); | |
1443 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1444 { | |
1445 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1446 save_preset_file(file_uri); | |
1447 g_free(file_uri); | |
1448 } | |
1449 | |
1450 songname = aud_playlist_get_filename(playlist, aud_playlist_get_position(playlist)); | |
1451 if (songname) { | |
1452 gchar *eqname = g_strdup_printf("%s.%s", songname, | |
1453 aud_cfg->eqpreset_extension); | |
1454 g_free(songname); | |
1455 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
1456 eqname); | |
1457 g_free(eqname); | |
1458 } | |
1459 | |
1460 gtk_widget_destroy(dialog); | |
1461 } | |
1462 | |
1463 void | |
1464 action_equ_save_preset_eqf(void) | |
1465 { | |
1466 GtkWidget *dialog; | |
1467 gchar *file_uri; | |
1468 | |
1469 dialog = make_filebrowser(Q_("Save equalizer preset"), TRUE); | |
1470 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1471 { | |
1472 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1473 save_winamp_file(file_uri); | |
1474 g_free(file_uri); | |
1475 } | |
1476 gtk_widget_destroy(dialog); | |
1477 } | |
1478 | |
1479 void | |
1480 action_equ_delete_preset(void) | |
1481 { | |
1482 if (equalizerwin_delete_window) { | |
1483 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window)); | |
1484 return; | |
1485 } | |
1486 | |
1487 equalizerwin_create_list_window(equalizer_presets, | |
1488 Q_("Delete preset"), | |
1489 &equalizerwin_delete_window, | |
1490 GTK_SELECTION_EXTENDED, NULL, | |
1491 GTK_STOCK_DELETE, | |
1492 G_CALLBACK(equalizerwin_delete_delete), | |
1493 NULL); | |
1494 } | |
1495 | |
1496 void | |
1497 action_equ_delete_auto_preset(void) | |
1498 { | |
1499 if (equalizerwin_delete_auto_window) { | |
1500 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window)); | |
1501 return; | |
1502 } | |
1503 | |
1504 equalizerwin_create_list_window(equalizer_auto_presets, | |
1505 Q_("Delete auto-preset"), | |
1506 &equalizerwin_delete_auto_window, | |
1507 GTK_SELECTION_EXTENDED, NULL, | |
1508 GTK_STOCK_DELETE, | |
1509 G_CALLBACK(equalizerwin_delete_auto_delete), | |
1510 NULL); | |
1511 } | |
1512 | |
1513 void | |
1514 equalizer_activate(gboolean active) | |
1515 { | |
1516 aud_cfg->equalizer_active = active; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
1517 ui_skinned_button_set_inside(equalizerwin_on, active); |
2606 | 1518 |
1519 equalizerwin_eq_changed(); | |
1520 } |