make sure closing the application aborts the remaining HttpGet objects. Should fix...
[Rockbox.git] / apps / menus / eq_menu.c
blob883c55d83001a579943e04386fb798b29c8b191d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: eq_menu.c 12179 2007-02-01 23:08:15Z amiconn $
10 * Copyright (C) 2006 Dan Everton
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
21 #include <stdio.h>
22 #include <stdbool.h>
23 #include <string.h>
24 #include "eq_menu.h"
25 #include "system.h"
26 #include "kernel.h"
27 #include "lcd.h"
28 #include "menu.h"
29 #include "action.h"
30 #include "mp3_playback.h"
31 #include "settings.h"
32 #include "statusbar.h"
33 #include "screens.h"
34 #include "icons.h"
35 #include "font.h"
36 #include "lang.h"
37 #include "sprintf.h"
38 #include "talk.h"
39 #include "misc.h"
40 #include "sound.h"
41 #include "splash.h"
42 #include "dsp.h"
43 #include "tree.h"
44 #include "talk.h"
45 #include "screen_access.h"
46 #include "keyboard.h"
47 #include "gui/scrollbar.h"
48 #include "eq_menu.h"
49 #ifdef HAVE_WM8758
50 #include "wm8758.h"
51 #endif
56 * Utility functions
59 void eq_gain_format(char* buffer, size_t buffer_size, int value, const char* unit)
61 int v = abs(value);
63 snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "",
64 v / EQ_USER_DIVISOR, v % EQ_USER_DIVISOR, unit);
67 void eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit)
69 snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
72 void eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit)
74 snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
75 value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
79 * Settings functions
81 int enable_callback(int action, const struct menu_item_ex *this_item)
83 int i;
84 (void)this_item;
85 if (action == ACTION_EXIT_MENUITEM)
87 dsp_set_eq(global_settings.eq_enabled);
88 dsp_set_eq_precut(global_settings.eq_precut);
89 /* Update all bands */
90 for(i = 0; i < 5; i++) {
91 dsp_set_eq_coefs(i);
94 return action;
96 MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, enable_callback);
97 MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, NULL);
99 int dsp_set_coefs_callback(int action, const struct menu_item_ex *this_item)
101 (void)this_item;
102 if (action == ACTION_EXIT_MENUITEM)
104 /* for now, set every band... figure out a better way later */
105 int i=0;
106 for (i=0; i<5; i++)
107 dsp_set_eq_coefs(i);
109 return action;
112 char* gainitem_get_name(int selected_item, void * data, char *buffer)
114 (void)selected_item;
115 int *setting = (int*)data;
116 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_GAIN_ITEM), *setting);
117 return buffer;
120 int do_option(void* param)
122 const struct menu_item_ex *setting = (const struct menu_item_ex*)param;
123 do_setting_from_menu(setting);
124 return 0;
127 MENUITEM_SETTING(cutoff_0, &global_settings.eq_band0_cutoff, dsp_set_coefs_callback);
128 MENUITEM_SETTING(cutoff_1, &global_settings.eq_band1_cutoff, dsp_set_coefs_callback);
129 MENUITEM_SETTING(cutoff_2, &global_settings.eq_band2_cutoff, dsp_set_coefs_callback);
130 MENUITEM_SETTING(cutoff_3, &global_settings.eq_band3_cutoff, dsp_set_coefs_callback);
131 MENUITEM_SETTING(cutoff_4, &global_settings.eq_band4_cutoff, dsp_set_coefs_callback);
133 MENUITEM_SETTING(q_0, &global_settings.eq_band0_q, dsp_set_coefs_callback);
134 MENUITEM_SETTING(q_1, &global_settings.eq_band1_q, dsp_set_coefs_callback);
135 MENUITEM_SETTING(q_2, &global_settings.eq_band2_q, dsp_set_coefs_callback);
136 MENUITEM_SETTING(q_3, &global_settings.eq_band3_q, dsp_set_coefs_callback);
137 MENUITEM_SETTING(q_4, &global_settings.eq_band4_q, dsp_set_coefs_callback);
139 MENUITEM_SETTING(gain_0, &global_settings.eq_band0_gain, dsp_set_coefs_callback);
140 MENUITEM_SETTING(gain_1, &global_settings.eq_band1_gain, dsp_set_coefs_callback);
141 MENUITEM_SETTING(gain_2, &global_settings.eq_band2_gain, dsp_set_coefs_callback);
142 MENUITEM_SETTING(gain_3, &global_settings.eq_band3_gain, dsp_set_coefs_callback);
143 MENUITEM_SETTING(gain_4, &global_settings.eq_band4_gain, dsp_set_coefs_callback);
145 MENUITEM_FUNCTION_DYNTEXT(gain_item_0, MENU_FUNC_USEPARAM, do_option, (void*)&gain_0,
146 gainitem_get_name, &global_settings.eq_band0_cutoff,
147 NULL, Icon_NOICON);
148 MENUITEM_FUNCTION_DYNTEXT(gain_item_1, MENU_FUNC_USEPARAM, do_option, (void*)&gain_1,
149 gainitem_get_name, &global_settings.eq_band1_cutoff,
150 NULL, Icon_NOICON);
151 MENUITEM_FUNCTION_DYNTEXT(gain_item_2, MENU_FUNC_USEPARAM, do_option, (void*)&gain_2,
152 gainitem_get_name, &global_settings.eq_band2_cutoff,
153 NULL, Icon_NOICON);
154 MENUITEM_FUNCTION_DYNTEXT(gain_item_3, MENU_FUNC_USEPARAM, do_option, (void*)&gain_3,
155 gainitem_get_name, &global_settings.eq_band3_cutoff,
156 NULL, Icon_NOICON);
157 MENUITEM_FUNCTION_DYNTEXT(gain_item_4, MENU_FUNC_USEPARAM, do_option, (void*)&gain_4,
158 gainitem_get_name, &global_settings.eq_band4_cutoff,
159 NULL, Icon_NOICON);
161 MAKE_MENU(gain_menu, ID2P(LANG_EQUALIZER_GAIN), NULL, Icon_NOICON, &gain_item_0,
162 &gain_item_1, &gain_item_2, &gain_item_3, &gain_item_4);
164 static const struct menu_item_ex *band_items[3][3] = {
165 { &cutoff_1, &q_1, &gain_1 },
166 { &cutoff_2, &q_2, &gain_2 },
167 { &cutoff_3, &q_3, &gain_3 }
169 char* centerband_get_name(int selected_item, void * data, char *buffer)
171 (void)selected_item;
172 int band = (intptr_t)data;
173 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band);
174 return buffer;
176 int do_center_band_menu(void* param)
178 int band = (intptr_t)param;
179 struct menu_item_ex menu;
180 struct menu_callback_with_desc cb_and_desc;
181 char desc[MAX_PATH];
183 cb_and_desc.menu_callback = NULL;
184 snprintf(desc, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band);
185 cb_and_desc.desc = desc;
186 cb_and_desc.icon_id = Icon_EQ;
187 menu.flags = MT_MENU|(3<<MENU_COUNT_SHIFT)|MENU_HAS_DESC;
188 menu.submenus = band_items[band-1];
189 menu.callback_and_desc = &cb_and_desc;
190 do_menu(&menu, NULL);
191 return 0;
193 MAKE_MENU(band_0_menu, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), NULL,
194 Icon_EQ, &cutoff_0, &q_0, &gain_0);
195 MENUITEM_FUNCTION_DYNTEXT(band_1_menu, MENU_FUNC_USEPARAM,
196 do_center_band_menu, (void*)1,
197 centerband_get_name, (void*)1, NULL, Icon_EQ);
198 MENUITEM_FUNCTION_DYNTEXT(band_2_menu, MENU_FUNC_USEPARAM,
199 do_center_band_menu, (void*)2,
200 centerband_get_name, (void*)2, NULL, Icon_EQ);
201 MENUITEM_FUNCTION_DYNTEXT(band_3_menu, MENU_FUNC_USEPARAM,
202 do_center_band_menu, (void*)3,
203 centerband_get_name, (void*)3, NULL, Icon_EQ);
204 MAKE_MENU(band_4_menu, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL,
205 Icon_EQ, &cutoff_4, &q_4, &gain_4);
207 MAKE_MENU(advanced_eq_menu_, ID2P(LANG_EQUALIZER_ADVANCED), NULL, Icon_EQ,
208 &band_0_menu, &band_1_menu, &band_2_menu, &band_3_menu, &band_4_menu);
211 enum eq_slider_mode {
212 GAIN,
213 CUTOFF,
217 enum eq_type {
218 LOW_SHELF,
219 PEAK,
220 HIGH_SHELF
223 /* Draw the UI for a whole EQ band */
224 static int draw_eq_slider(struct screen * screen, int x, int y,
225 int width, int cutoff, int q, int gain, bool selected,
226 enum eq_slider_mode mode, enum eq_type type)
228 char buf[26];
229 const char separator[2] = " ";
230 int steps, min_item, max_item;
231 int abs_gain = abs(gain);
232 int current_x, total_height, separator_width, separator_height;
233 int w, h;
234 const int slider_height = 6;
236 switch(mode) {
237 case Q:
238 steps = EQ_Q_MAX - EQ_Q_MIN;
239 min_item = q - EQ_Q_STEP - EQ_Q_MIN;
240 max_item = q + EQ_Q_STEP - EQ_Q_MIN;
241 break;
242 case CUTOFF:
243 steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN;
244 min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2;
245 max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2;
246 break;
247 case GAIN:
248 default:
249 steps = EQ_GAIN_MAX - EQ_GAIN_MIN;
250 min_item = abs(EQ_GAIN_MIN) + gain - EQ_GAIN_STEP * 5;
251 max_item = abs(EQ_GAIN_MIN) + gain + EQ_GAIN_STEP * 5;
252 break;
255 /* Start two pixels in, one for border, one for margin */
256 current_x = x + 2;
258 /* Figure out how large our separator string is */
259 screen->getstringsize(separator, &separator_width, &separator_height);
261 /* Total height includes margins, text, and line selector */
262 total_height = separator_height + slider_height + 2 + 3;
264 /* Print out the band label */
265 if (type == LOW_SHELF) {
266 screen->putsxy(current_x, y + 2, "LS:");
267 screen->getstringsize("LS:", &w, &h);
268 } else if (type == HIGH_SHELF) {
269 screen->putsxy(current_x, y + 2, "HS:");
270 screen->getstringsize("HS:", &w, &h);
271 } else {
272 screen->putsxy(current_x, y + 2, "PK:");
273 screen->getstringsize("PK:", &w, &h);
275 current_x += w;
277 /* Print separator */
278 screen->set_drawmode(DRMODE_SOLID);
279 screen->putsxy(current_x, y + 2, separator);
280 current_x += separator_width;
281 #if NB_SCREENS > 1
282 if (screen->screen_type == SCREEN_REMOTE) {
283 if (mode == GAIN) {
284 screen->putsxy(current_x, y + 2, str(LANG_GAIN));
285 screen->getstringsize(str(LANG_GAIN), &w, &h);
286 } else if (mode == CUTOFF) {
287 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_CUTOFF));
288 screen->getstringsize(str(LANG_EQUALIZER_BAND_CUTOFF), &w, &h);
289 } else {
290 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_Q));
291 screen->getstringsize(str(LANG_EQUALIZER_BAND_Q), &w, &h);
294 /* Draw horizontal slider. Reuse scrollbar for this */
295 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
296 min_item, max_item, HORIZONTAL);
298 /* Print out cutoff part */
299 snprintf(buf, sizeof(buf), "%sGain %s%2d.%ddB",mode==GAIN?" > ":" ", gain < 0 ? "-" : " ",
300 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
301 screen->getstringsize(buf, &w, &h);
302 y = 3*h;
303 screen->putsxy(0, y, buf);
304 /* Print out cutoff part */
305 snprintf(buf, sizeof(buf), "%sCutoff %5dHz",mode==CUTOFF?" > ":" ", cutoff);
306 y += h;
307 screen->putsxy(0, y, buf);
308 snprintf(buf, sizeof(buf), "%sQ setting %d.%d Q",mode==Q?" > ":" ", q / EQ_USER_DIVISOR,
309 q % EQ_USER_DIVISOR);
310 y += h;
311 screen->putsxy(0, y, buf);
312 return y;
314 #endif
316 /* Print out gain part of status line */
317 snprintf(buf, sizeof(buf), "%s%2d.%ddB", gain < 0 ? "-" : " ",
318 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
320 if (mode == GAIN && selected)
321 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
323 screen->putsxy(current_x, y + 2, buf);
324 screen->getstringsize(buf, &w, &h);
325 current_x += w;
327 /* Print separator */
328 screen->set_drawmode(DRMODE_SOLID);
329 screen->putsxy(current_x, y + 2, separator);
330 current_x += separator_width;
332 /* Print out cutoff part of status line */
333 snprintf(buf, sizeof(buf), "%5dHz", cutoff);
335 if (mode == CUTOFF && selected)
336 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
338 screen->putsxy(current_x, y + 2, buf);
339 screen->getstringsize(buf, &w, &h);
340 current_x += w;
342 /* Print separator */
343 screen->set_drawmode(DRMODE_SOLID);
344 screen->putsxy(current_x, y + 2, separator);
345 current_x += separator_width;
347 /* Print out Q part of status line */
348 snprintf(buf, sizeof(buf), "%d.%d Q", q / EQ_USER_DIVISOR,
349 q % EQ_USER_DIVISOR);
351 if (mode == Q && selected)
352 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
354 screen->putsxy(current_x, y + 2, buf);
355 screen->getstringsize(buf, &w, &h);
356 current_x += w;
358 screen->set_drawmode(DRMODE_SOLID);
360 /* Draw selection box */
361 if (selected) {
362 screen->drawrect(x, y, width, total_height);
365 /* Draw horizontal slider. Reuse scrollbar for this */
366 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
367 min_item, max_item, HORIZONTAL);
369 return total_height;
372 /* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
373 static int draw_eq_sliders(int current_band, enum eq_slider_mode mode)
375 int i, gain, q, cutoff;
376 int height = 2; /* Two pixel margin */
377 int slider_width[NB_SCREENS];
378 int *setting = &global_settings.eq_band0_cutoff;
379 enum eq_type type;
381 FOR_NB_SCREENS(i)
382 slider_width[i] = screens[i].width - 4; /* two pixel margin on each side */
384 for (i=0; i<5; i++) {
385 cutoff = *setting++;
386 q = *setting++;
387 gain = *setting++;
389 if (i == 0) {
390 type = LOW_SHELF;
391 } else if (i == 4) {
392 type = HIGH_SHELF;
393 } else {
394 type = PEAK;
396 height += draw_eq_slider(&(screens[SCREEN_MAIN]), 2, height,
397 slider_width[SCREEN_MAIN], cutoff, q, gain,
398 i == current_band, mode, type);
399 #if NB_SCREENS > 1
400 if (i == current_band)
401 draw_eq_slider(&(screens[SCREEN_REMOTE]), 2, 0,
402 slider_width[SCREEN_REMOTE], cutoff, q, gain,1, mode, type);
403 #endif
404 /* add a margin */
405 height += 2;
408 return height;
411 /* Provides a graphical means of editing the EQ settings */
412 bool eq_menu_graphical(void)
414 bool exit_request = false;
415 bool result = true;
416 bool has_changed = false;
417 int button;
418 int *setting;
419 int current_band, y, step, fast_step, min, max, voice_unit;
420 enum eq_slider_mode mode;
421 enum eq_type current_type;
422 char buf[24];
423 int i;
425 FOR_NB_SCREENS(i) {
426 screens[i].setfont(FONT_SYSFIXED);
427 screens[i].clear_display();
430 /* Start off editing gain on the first band */
431 mode = GAIN;
432 current_type = LOW_SHELF;
433 current_band = 0;
435 while (!exit_request) {
437 FOR_NB_SCREENS(i) {
438 /* Clear the screen. The drawing routines expect this */
439 screens[i].clear_display();
440 /* Draw equalizer band details */
441 y = draw_eq_sliders(current_band, mode);
444 /* Set pointer to the band data currently editable */
445 if (mode == GAIN) {
446 /* gain */
447 setting = &global_settings.eq_band0_gain;
448 setting += current_band * 3;
450 step = EQ_GAIN_STEP;
451 fast_step = EQ_GAIN_FAST_STEP;
452 min = EQ_GAIN_MIN;
453 max = EQ_GAIN_MAX;
454 voice_unit = UNIT_DB;
456 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
457 str(LANG_SYSFONT_GAIN));
459 screens[SCREEN_MAIN].putsxy(2, y, buf);
460 } else if (mode == CUTOFF) {
461 /* cutoff */
462 setting = &global_settings.eq_band0_cutoff;
463 setting += current_band * 3;
465 step = EQ_CUTOFF_STEP;
466 fast_step = EQ_CUTOFF_FAST_STEP;
467 min = EQ_CUTOFF_MIN;
468 max = EQ_CUTOFF_MAX;
469 voice_unit = UNIT_HERTZ;
471 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
472 str(LANG_SYSFONT_EQUALIZER_BAND_CUTOFF));
474 screens[SCREEN_MAIN].putsxy(2, y, buf);
475 } else {
476 /* Q */
477 setting = &global_settings.eq_band0_q;
478 setting += current_band * 3;
480 step = EQ_Q_STEP;
481 fast_step = EQ_Q_FAST_STEP;
482 min = EQ_Q_MIN;
483 max = EQ_Q_MAX;
484 voice_unit = UNIT_INT;
486 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
487 str(LANG_EQUALIZER_BAND_Q));
489 screens[SCREEN_MAIN].putsxy(2, y, buf);
492 FOR_NB_SCREENS(i) {
493 screens[i].update();
496 button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK);
498 switch (button) {
499 case ACTION_SETTINGS_DEC:
500 case ACTION_SETTINGS_DECREPEAT:
501 *(setting) -= step;
502 has_changed = true;
503 if (*(setting) < min)
504 *(setting) = min;
505 break;
507 case ACTION_SETTINGS_INC:
508 case ACTION_SETTINGS_INCREPEAT:
509 *(setting) += step;
510 has_changed = true;
511 if (*(setting) > max)
512 *(setting) = max;
513 break;
515 case ACTION_SETTINGS_INCBIGSTEP:
516 *(setting) += fast_step;
517 has_changed = true;
518 if (*(setting) > max)
519 *(setting) = max;
520 break;
522 case ACTION_SETTINGS_DECBIGSTEP:
523 *(setting) -= fast_step;
524 has_changed = true;
525 if (*(setting) < min)
526 *(setting) = min;
527 break;
529 case ACTION_STD_PREV:
530 case ACTION_STD_PREVREPEAT:
531 current_band--;
532 if (current_band < 0)
533 current_band = 4; /* wrap around */
534 break;
536 case ACTION_STD_NEXT:
537 case ACTION_STD_NEXTREPEAT:
538 current_band++;
539 if (current_band > 4)
540 current_band = 0; /* wrap around */
541 break;
543 case ACTION_STD_OK:
544 mode++;
545 if (mode > Q)
546 mode = GAIN; /* wrap around */
547 break;
549 case ACTION_STD_CANCEL:
550 exit_request = true;
551 result = false;
552 break;
554 default:
555 if(default_event_handler(button) == SYS_USB_CONNECTED) {
556 exit_request = true;
557 result = true;
559 break;
562 /* Update the filter if the user changed something */
563 if (has_changed) {
564 dsp_set_eq_coefs(current_band);
565 has_changed = false;
569 /* Reset screen settings */
570 FOR_NB_SCREENS(i) {
571 screens[i].setfont(FONT_UI);
572 screens[i].clear_display();
574 return result;
577 /* Preset saver.
578 * TODO: Can the settings system be used to do this instead?
580 static bool eq_save_preset(void)
582 int fd, i;
583 char filename[MAX_PATH];
584 int *setting;
586 create_numbered_filename(filename, EQS_DIR, "eq", ".cfg", 2
587 IF_CNFN_NUM_(, NULL));
589 /* allow user to modify filename */
590 while (true) {
591 if (!kbd_input(filename, sizeof filename)) {
592 fd = creat(filename);
593 if (fd < 0)
594 gui_syncsplash(HZ, str(LANG_FAILED));
595 else
596 break;
598 else {
599 gui_syncsplash(HZ, str(LANG_CANCEL));
600 return false;
604 /* TODO: Should we really do this? */
605 fdprintf(fd, "eq enabled: on\r\n");
606 fdprintf(fd, "eq precut: %d\r\n", global_settings.eq_precut);
608 setting = &global_settings.eq_band0_cutoff;
610 for(i = 0; i < 5; ++i) {
611 fdprintf(fd, "eq band %d cutoff: %d\r\n", i, *setting++);
612 fdprintf(fd, "eq band %d q: %d\r\n", i, *setting++);
613 fdprintf(fd, "eq band %d gain: %d\r\n", i, *setting++);
616 close(fd);
618 gui_syncsplash(HZ, str(LANG_SETTINGS_SAVED));
620 return true;
623 /* Allows browsing of preset files */
624 bool eq_browse_presets(void)
626 return rockbox_browse(EQS_DIR, SHOW_CFG);
630 MENUITEM_FUNCTION(eq_graphical, 0, ID2P(LANG_EQUALIZER_GRAPHICAL),
631 (int(*)(void))eq_menu_graphical, NULL, NULL,
632 Icon_EQ);
633 MENUITEM_FUNCTION(eq_save, 0, ID2P(LANG_EQUALIZER_SAVE),
634 (int(*)(void))eq_save_preset, NULL, NULL, Icon_NOICON);
635 MENUITEM_FUNCTION(eq_browse, 0, ID2P(LANG_EQUALIZER_BROWSE),
636 (int(*)(void))eq_browse_presets, NULL, NULL, Icon_NOICON);
638 int soundmenu_callback(int action,const struct menu_item_ex *this_item);
639 MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), soundmenu_callback, Icon_EQ,
640 &eq_enable, &eq_graphical, &eq_precut, &gain_menu,
641 &advanced_eq_menu_, &eq_save, &eq_browse);
644 #ifdef HAVE_WM8758
646 void eq_hw_gain_format(char* buffer, size_t buffer_size, int value,
647 const char* unit)
649 snprintf(buffer, buffer_size, "%d %s", value, unit);
652 static int band0_callback(int action, const struct menu_item_ex *this_item)
654 (void)this_item;
655 if (action == ACTION_EXIT_MENUITEM)
657 #ifndef SIMULATOR
658 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff, 0,
659 global_settings.eq_hw_band0_gain);
660 #endif
662 return action;
664 static int band1_callback(int action, const struct menu_item_ex *this_item)
666 (void)this_item;
667 if (action == ACTION_EXIT_MENUITEM)
669 #ifndef SIMULATOR
670 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
671 global_settings.eq_hw_band1_bandwidth,
672 global_settings.eq_hw_band1_gain);
673 #endif
675 return action;
677 static int band2_callback(int action, const struct menu_item_ex *this_item)
679 (void)this_item;
680 if (action == ACTION_EXIT_MENUITEM)
682 #ifndef SIMULATOR
683 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
684 global_settings.eq_hw_band2_bandwidth,
685 global_settings.eq_hw_band2_gain);
686 #endif
688 return action;
690 static int band3_callback(int action, const struct menu_item_ex *this_item)
692 (void)this_item;
693 if (action == ACTION_EXIT_MENUITEM)
695 #ifndef SIMULATOR
696 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
697 global_settings.eq_hw_band3_bandwidth,
698 global_settings.eq_hw_band3_gain);
699 #endif
701 return action;
703 static int band4_callback(int action, const struct menu_item_ex *this_item)
705 (void)this_item;
706 if (action == ACTION_EXIT_MENUITEM)
708 #ifndef SIMULATOR
709 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff, 0,
710 global_settings.eq_hw_band4_gain);
711 #endif
713 return action;
715 void eq_hw_enable(bool enable)
717 #ifdef SIMULATOR
718 (void) enable;
719 #else
720 if (enable) {
721 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff,
722 0, global_settings.eq_hw_band0_gain);
723 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
724 global_settings.eq_hw_band1_bandwidth,
725 global_settings.eq_hw_band1_gain);
726 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
727 global_settings.eq_hw_band2_bandwidth,
728 global_settings.eq_hw_band2_gain);
729 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
730 global_settings.eq_hw_band3_bandwidth,
731 global_settings.eq_hw_band3_gain);
732 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff,
733 0, global_settings.eq_hw_band4_gain);
734 } else {
735 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff, 0, 0);
736 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
737 global_settings.eq_hw_band1_bandwidth, 0);
738 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
739 global_settings.eq_hw_band2_bandwidth, 0);
740 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
741 global_settings.eq_hw_band3_bandwidth, 0);
742 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff, 0, 0);
744 #endif
746 static int hweq_enable_callback(int action, const struct menu_item_ex *this_item)
748 (void)this_item;
749 if (action == ACTION_EXIT_MENUITEM)
751 eq_hw_enable(global_settings.eq_hw_enabled);
753 return action;
755 MENUITEM_SETTING(hw_eq_enable, &global_settings.eq_hw_enabled, hweq_enable_callback);
757 MENUITEM_SETTING(hw_eq_cutoff_0, &global_settings.eq_hw_band0_cutoff, band0_callback);
758 MENUITEM_SETTING(hw_eq_gain_0, &global_settings.eq_hw_band0_gain, band0_callback);
759 MAKE_MENU(hw_eq_band0, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), NULL, Icon_NOICON,
760 &hw_eq_cutoff_0, &hw_eq_gain_0);
762 MENUITEM_SETTING(hw_eq_cutoff_1, &global_settings.eq_hw_band1_center, band1_callback);
763 MENUITEM_SETTING(hw_eq_bandwidth_1, &global_settings.eq_hw_band1_bandwidth, band1_callback);
764 MENUITEM_SETTING(hw_eq_gain_1, &global_settings.eq_hw_band1_gain, band1_callback);
765 MAKE_MENU(hw_eq_band1, "Peak Filter 1", NULL, Icon_NOICON,
766 &hw_eq_cutoff_1, &hw_eq_bandwidth_1, &hw_eq_gain_1);
768 MENUITEM_SETTING(hw_eq_cutoff_2, &global_settings.eq_hw_band2_center, band2_callback);
769 MENUITEM_SETTING(hw_eq_bandwidth_2, &global_settings.eq_hw_band2_bandwidth, band2_callback);
770 MENUITEM_SETTING(hw_eq_gain_2, &global_settings.eq_hw_band2_gain, band2_callback);
771 MAKE_MENU(hw_eq_band2, "Peak Filter 2", NULL, Icon_NOICON,
772 &hw_eq_cutoff_2, &hw_eq_bandwidth_2, &hw_eq_gain_2);
774 MENUITEM_SETTING(hw_eq_cutoff_3, &global_settings.eq_hw_band3_center, band3_callback);
775 MENUITEM_SETTING(hw_eq_bandwidth_3, &global_settings.eq_hw_band3_bandwidth, band3_callback);
776 MENUITEM_SETTING(hw_eq_gain_3, &global_settings.eq_hw_band3_gain, band3_callback);
777 MAKE_MENU(hw_eq_band3, "Peak Filter 3", NULL, Icon_NOICON,
778 &hw_eq_cutoff_3, &hw_eq_bandwidth_3, &hw_eq_gain_3);
780 MENUITEM_SETTING(hw_eq_cutoff_4, &global_settings.eq_hw_band4_cutoff, band4_callback);
781 MENUITEM_SETTING(hw_eq_gain_4, &global_settings.eq_hw_band4_gain, band4_callback);
782 MAKE_MENU(hw_eq_band4, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL, Icon_NOICON,
783 &hw_eq_cutoff_4, &hw_eq_gain_4);
785 MAKE_MENU(hw_eq_menu, ID2P(LANG_EQUALIZER_HARDWARE), NULL, Icon_EQ,
786 &hw_eq_enable, &hw_eq_band0, &hw_eq_band1,
787 &hw_eq_band2, &hw_eq_band3, &hw_eq_band4);
790 #endif