Get rid of the 'center' parameter for splashes. There were only 2 of almost 500 splas...
[Rockbox.git] / apps / menus / eq_menu.c
blob0cf63bb20de067c412ae92d05c64aebde4f41bc0
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, int 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, int 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, int 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_WPARAM_DYNTEXT(gain_item_0, do_option, (void*)&gain_0, NULL,
146 gainitem_get_name,
147 &global_settings.eq_band0_cutoff, Icon_NOICON);
148 MENUITEM_FUNCTION_WPARAM_DYNTEXT(gain_item_1, do_option, (void*)&gain_1, NULL,
149 gainitem_get_name,
150 &global_settings.eq_band1_cutoff, Icon_NOICON);
151 MENUITEM_FUNCTION_WPARAM_DYNTEXT(gain_item_2, do_option, (void*)&gain_2, NULL,
152 gainitem_get_name,
153 &global_settings.eq_band2_cutoff, Icon_NOICON);
154 MENUITEM_FUNCTION_WPARAM_DYNTEXT(gain_item_3, do_option, (void*)&gain_3, NULL,
155 gainitem_get_name,
156 &global_settings.eq_band3_cutoff, Icon_NOICON);
157 MENUITEM_FUNCTION_WPARAM_DYNTEXT(gain_item_4, do_option, (void*)&gain_4, NULL,
158 gainitem_get_name,
159 &global_settings.eq_band4_cutoff, 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_WPARAM_DYNTEXT(band_1_menu, do_center_band_menu, (void*)1, NULL,
196 centerband_get_name, (void*)1, Icon_EQ);
197 MENUITEM_FUNCTION_WPARAM_DYNTEXT(band_2_menu, do_center_band_menu, (void*)2, NULL,
198 centerband_get_name, (void*)2, Icon_EQ);
199 MENUITEM_FUNCTION_WPARAM_DYNTEXT(band_3_menu, do_center_band_menu, (void*)3, NULL,
200 centerband_get_name, (void*)3, Icon_EQ);
201 MAKE_MENU(band_4_menu, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL,
202 Icon_EQ, &cutoff_4, &q_4, &gain_4);
204 MAKE_MENU(advanced_eq_menu_, ID2P(LANG_EQUALIZER_ADVANCED), NULL, Icon_EQ,
205 &band_0_menu, &band_1_menu, &band_2_menu, &band_3_menu, &band_4_menu);
208 enum eq_slider_mode {
209 GAIN,
210 CUTOFF,
214 enum eq_type {
215 LOW_SHELF,
216 PEAK,
217 HIGH_SHELF
220 /* Draw the UI for a whole EQ band */
221 static int draw_eq_slider(struct screen * screen, int x, int y,
222 int width, int cutoff, int q, int gain, bool selected,
223 enum eq_slider_mode mode, enum eq_type type)
225 char buf[26];
226 const char separator[2] = " ";
227 int steps, min_item, max_item;
228 int abs_gain = abs(gain);
229 int current_x, total_height, separator_width, separator_height;
230 int w, h;
231 const int slider_height = 6;
233 switch(mode) {
234 case Q:
235 steps = EQ_Q_MAX - EQ_Q_MIN;
236 min_item = q - EQ_Q_STEP - EQ_Q_MIN;
237 max_item = q + EQ_Q_STEP - EQ_Q_MIN;
238 break;
239 case CUTOFF:
240 steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN;
241 min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2;
242 max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2;
243 break;
244 case GAIN:
245 default:
246 steps = EQ_GAIN_MAX - EQ_GAIN_MIN;
247 min_item = abs(EQ_GAIN_MIN) + gain - EQ_GAIN_STEP * 5;
248 max_item = abs(EQ_GAIN_MIN) + gain + EQ_GAIN_STEP * 5;
249 break;
252 /* Start two pixels in, one for border, one for margin */
253 current_x = x + 2;
255 /* Figure out how large our separator string is */
256 screen->getstringsize(separator, &separator_width, &separator_height);
258 /* Total height includes margins, text, and line selector */
259 total_height = separator_height + slider_height + 2 + 3;
261 /* Print out the band label */
262 if (type == LOW_SHELF) {
263 screen->putsxy(current_x, y + 2, "LS:");
264 screen->getstringsize("LS:", &w, &h);
265 } else if (type == HIGH_SHELF) {
266 screen->putsxy(current_x, y + 2, "HS:");
267 screen->getstringsize("HS:", &w, &h);
268 } else {
269 screen->putsxy(current_x, y + 2, "PK:");
270 screen->getstringsize("PK:", &w, &h);
272 current_x += w;
274 /* Print separator */
275 screen->set_drawmode(DRMODE_SOLID);
276 screen->putsxy(current_x, y + 2, separator);
277 current_x += separator_width;
278 #if NB_SCREENS > 1
279 if (screen->screen_type == SCREEN_REMOTE) {
280 if (mode == GAIN) {
281 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_GAIN));
282 screen->getstringsize(str(LANG_EQUALIZER_BAND_GAIN), &w, &h);
283 } else if (mode == CUTOFF) {
284 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_CUTOFF));
285 screen->getstringsize(str(LANG_EQUALIZER_BAND_CUTOFF), &w, &h);
286 } else {
287 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_Q));
288 screen->getstringsize(str(LANG_EQUALIZER_BAND_Q), &w, &h);
291 /* Draw horizontal slider. Reuse scrollbar for this */
292 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
293 min_item, max_item, HORIZONTAL);
295 /* Print out cutoff part */
296 snprintf(buf, sizeof(buf), "%sGain %s%2d.%ddB",mode==GAIN?" > ":" ", gain < 0 ? "-" : " ",
297 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
298 screen->getstringsize(buf, &w, &h);
299 y = 3*h;
300 screen->putsxy(0, y, buf);
301 /* Print out cutoff part */
302 snprintf(buf, sizeof(buf), "%sCutoff %5dHz",mode==CUTOFF?" > ":" ", cutoff);
303 y += h;
304 screen->putsxy(0, y, buf);
305 snprintf(buf, sizeof(buf), "%sQ setting %d.%d Q",mode==Q?" > ":" ", q / EQ_USER_DIVISOR,
306 q % EQ_USER_DIVISOR);
307 y += h;
308 screen->putsxy(0, y, buf);
309 return y;
311 #endif
313 /* Print out gain part of status line */
314 snprintf(buf, sizeof(buf), "%s%2d.%ddB", gain < 0 ? "-" : " ",
315 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
317 if (mode == GAIN && selected)
318 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
320 screen->putsxy(current_x, y + 2, buf);
321 screen->getstringsize(buf, &w, &h);
322 current_x += w;
324 /* Print separator */
325 screen->set_drawmode(DRMODE_SOLID);
326 screen->putsxy(current_x, y + 2, separator);
327 current_x += separator_width;
329 /* Print out cutoff part of status line */
330 snprintf(buf, sizeof(buf), "%5dHz", cutoff);
332 if (mode == CUTOFF && selected)
333 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
335 screen->putsxy(current_x, y + 2, buf);
336 screen->getstringsize(buf, &w, &h);
337 current_x += w;
339 /* Print separator */
340 screen->set_drawmode(DRMODE_SOLID);
341 screen->putsxy(current_x, y + 2, separator);
342 current_x += separator_width;
344 /* Print out Q part of status line */
345 snprintf(buf, sizeof(buf), "%d.%d Q", q / EQ_USER_DIVISOR,
346 q % EQ_USER_DIVISOR);
348 if (mode == Q && selected)
349 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
351 screen->putsxy(current_x, y + 2, buf);
352 screen->getstringsize(buf, &w, &h);
353 current_x += w;
355 screen->set_drawmode(DRMODE_SOLID);
357 /* Draw selection box */
358 if (selected) {
359 screen->drawrect(x, y, width, total_height);
362 /* Draw horizontal slider. Reuse scrollbar for this */
363 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
364 min_item, max_item, HORIZONTAL);
366 return total_height;
369 /* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
370 static int draw_eq_sliders(int current_band, enum eq_slider_mode mode)
372 int i, gain, q, cutoff;
373 int height = 2; /* Two pixel margin */
374 int slider_width[NB_SCREENS];
375 int *setting = &global_settings.eq_band0_cutoff;
376 enum eq_type type;
378 FOR_NB_SCREENS(i)
379 slider_width[i] = screens[i].width - 4; /* two pixel margin on each side */
381 for (i=0; i<5; i++) {
382 cutoff = *setting++;
383 q = *setting++;
384 gain = *setting++;
386 if (i == 0) {
387 type = LOW_SHELF;
388 } else if (i == 4) {
389 type = HIGH_SHELF;
390 } else {
391 type = PEAK;
393 height += draw_eq_slider(&(screens[SCREEN_MAIN]), 2, height,
394 slider_width[SCREEN_MAIN], cutoff, q, gain,
395 i == current_band, mode, type);
396 #if NB_SCREENS > 1
397 if (i == current_band)
398 draw_eq_slider(&(screens[SCREEN_REMOTE]), 2, 0,
399 slider_width[SCREEN_REMOTE], cutoff, q, gain,1, mode, type);
400 #endif
401 /* add a margin */
402 height += 2;
405 return height;
408 /* Provides a graphical means of editing the EQ settings */
409 bool eq_menu_graphical(void)
411 bool exit_request = false;
412 bool result = true;
413 bool has_changed = false;
414 int button;
415 int *setting;
416 int current_band, y, step, fast_step, min, max, voice_unit;
417 enum eq_slider_mode mode;
418 enum eq_type current_type;
419 char buf[24];
420 int i;
422 FOR_NB_SCREENS(i) {
423 screens[i].setfont(FONT_SYSFIXED);
424 screens[i].clear_display();
427 /* Start off editing gain on the first band */
428 mode = GAIN;
429 current_type = LOW_SHELF;
430 current_band = 0;
432 while (!exit_request) {
434 FOR_NB_SCREENS(i) {
435 /* Clear the screen. The drawing routines expect this */
436 screens[i].clear_display();
437 /* Draw equalizer band details */
438 y = draw_eq_sliders(current_band, mode);
441 /* Set pointer to the band data currently editable */
442 if (mode == GAIN) {
443 /* gain */
444 setting = &global_settings.eq_band0_gain;
445 setting += current_band * 3;
447 step = EQ_GAIN_STEP;
448 fast_step = EQ_GAIN_FAST_STEP;
449 min = EQ_GAIN_MIN;
450 max = EQ_GAIN_MAX;
451 voice_unit = UNIT_DB;
453 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
454 str(LANG_SYSFONT_EQUALIZER_BAND_GAIN));
456 screens[SCREEN_MAIN].putsxy(2, y, buf);
457 } else if (mode == CUTOFF) {
458 /* cutoff */
459 setting = &global_settings.eq_band0_cutoff;
460 setting += current_band * 3;
462 step = EQ_CUTOFF_STEP;
463 fast_step = EQ_CUTOFF_FAST_STEP;
464 min = EQ_CUTOFF_MIN;
465 max = EQ_CUTOFF_MAX;
466 voice_unit = UNIT_HERTZ;
468 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
469 str(LANG_SYSFONT_EQUALIZER_BAND_CUTOFF));
471 screens[SCREEN_MAIN].putsxy(2, y, buf);
472 } else {
473 /* Q */
474 setting = &global_settings.eq_band0_q;
475 setting += current_band * 3;
477 step = EQ_Q_STEP;
478 fast_step = EQ_Q_FAST_STEP;
479 min = EQ_Q_MIN;
480 max = EQ_Q_MAX;
481 voice_unit = UNIT_INT;
483 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
484 str(LANG_EQUALIZER_BAND_Q));
486 screens[SCREEN_MAIN].putsxy(2, y, buf);
489 FOR_NB_SCREENS(i) {
490 screens[i].update();
493 button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK);
495 switch (button) {
496 case ACTION_SETTINGS_DEC:
497 case ACTION_SETTINGS_DECREPEAT:
498 *(setting) -= step;
499 has_changed = true;
500 if (*(setting) < min)
501 *(setting) = min;
502 break;
504 case ACTION_SETTINGS_INC:
505 case ACTION_SETTINGS_INCREPEAT:
506 *(setting) += step;
507 has_changed = true;
508 if (*(setting) > max)
509 *(setting) = max;
510 break;
512 case ACTION_SETTINGS_INCBIGSTEP:
513 *(setting) += fast_step;
514 has_changed = true;
515 if (*(setting) > max)
516 *(setting) = max;
517 break;
519 case ACTION_SETTINGS_DECBIGSTEP:
520 *(setting) -= fast_step;
521 has_changed = true;
522 if (*(setting) < min)
523 *(setting) = min;
524 break;
526 case ACTION_STD_PREV:
527 case ACTION_STD_PREVREPEAT:
528 current_band--;
529 if (current_band < 0)
530 current_band = 4; /* wrap around */
531 break;
533 case ACTION_STD_NEXT:
534 case ACTION_STD_NEXTREPEAT:
535 current_band++;
536 if (current_band > 4)
537 current_band = 0; /* wrap around */
538 break;
540 case ACTION_STD_OK:
541 mode++;
542 if (mode > Q)
543 mode = GAIN; /* wrap around */
544 break;
546 case ACTION_STD_CANCEL:
547 exit_request = true;
548 result = false;
549 break;
551 default:
552 if(default_event_handler(button) == SYS_USB_CONNECTED) {
553 exit_request = true;
554 result = true;
556 break;
559 /* Update the filter if the user changed something */
560 if (has_changed) {
561 dsp_set_eq_coefs(current_band);
562 has_changed = false;
566 action_signalscreenchange();
567 /* Reset screen settings */
568 FOR_NB_SCREENS(i) {
569 screens[i].setfont(FONT_UI);
570 screens[i].clear_display();
572 return result;
575 /* Preset saver.
576 * TODO: Can the settings system be used to do this instead?
578 static bool eq_save_preset(void)
580 int fd, i;
581 char filename[MAX_PATH];
582 int *setting;
584 create_numbered_filename(filename, EQS_DIR, "eq", ".cfg", 2
585 IF_CNFN_NUM_(, NULL));
587 /* allow user to modify filename */
588 while (true) {
589 if (!kbd_input(filename, sizeof filename)) {
590 fd = creat(filename);
591 if (fd < 0)
592 gui_syncsplash(HZ, str(LANG_FAILED));
593 else
594 break;
596 else {
597 gui_syncsplash(HZ, str(LANG_MENU_SETTING_CANCEL));
598 return false;
602 /* TODO: Should we really do this? */
603 fdprintf(fd, "eq enabled: on\r\n");
604 fdprintf(fd, "eq precut: %d\r\n", global_settings.eq_precut);
606 setting = &global_settings.eq_band0_cutoff;
608 for(i = 0; i < 5; ++i) {
609 fdprintf(fd, "eq band %d cutoff: %d\r\n", i, *setting++);
610 fdprintf(fd, "eq band %d q: %d\r\n", i, *setting++);
611 fdprintf(fd, "eq band %d gain: %d\r\n", i, *setting++);
614 close(fd);
616 gui_syncsplash(HZ, str(LANG_SETTINGS_SAVED));
618 return true;
621 /* Allows browsing of preset files */
622 bool eq_browse_presets(void)
624 return rockbox_browse(EQS_DIR, SHOW_CFG);
628 MENUITEM_FUNCTION(eq_graphical, ID2P(LANG_EQUALIZER_GRAPHICAL),
629 (int(*)(void))eq_menu_graphical, NULL,
630 Icon_EQ);
631 MENUITEM_FUNCTION(eq_save, ID2P(LANG_EQUALIZER_SAVE),
632 (int(*)(void))eq_save_preset, NULL, Icon_NOICON);
633 MENUITEM_FUNCTION(eq_browse, ID2P(LANG_EQUALIZER_BROWSE),
634 (int(*)(void))eq_browse_presets, NULL, Icon_NOICON);
636 MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), NULL, Icon_EQ,
637 &eq_enable, &eq_graphical, &eq_precut, &gain_menu,
638 &advanced_eq_menu_, &eq_save, &eq_browse);
641 #ifdef HAVE_WM8758
643 void eq_hw_gain_format(char* buffer, int buffer_size, int value,
644 const char* unit)
646 snprintf(buffer, buffer_size, "%d %s", value, unit);
649 static int band0_callback(int action, const struct menu_item_ex *this_item)
651 (void)this_item;
652 if (action == ACTION_EXIT_MENUITEM)
654 #ifndef SIMULATOR
655 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff, 0,
656 global_settings.eq_hw_band0_gain);
657 #endif
659 return action;
661 static int band1_callback(int action, const struct menu_item_ex *this_item)
663 (void)this_item;
664 if (action == ACTION_EXIT_MENUITEM)
666 #ifndef SIMULATOR
667 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
668 global_settings.eq_hw_band1_bandwidth,
669 global_settings.eq_hw_band1_gain);
670 #endif
672 return action;
674 static int band2_callback(int action, const struct menu_item_ex *this_item)
676 (void)this_item;
677 if (action == ACTION_EXIT_MENUITEM)
679 #ifndef SIMULATOR
680 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
681 global_settings.eq_hw_band2_bandwidth,
682 global_settings.eq_hw_band2_gain);
683 #endif
685 return action;
687 static int band3_callback(int action, const struct menu_item_ex *this_item)
689 (void)this_item;
690 if (action == ACTION_EXIT_MENUITEM)
692 #ifndef SIMULATOR
693 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
694 global_settings.eq_hw_band3_bandwidth,
695 global_settings.eq_hw_band3_gain);
696 #endif
698 return action;
700 static int band4_callback(int action, const struct menu_item_ex *this_item)
702 (void)this_item;
703 if (action == ACTION_EXIT_MENUITEM)
705 #ifndef SIMULATOR
706 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff, 0,
707 global_settings.eq_hw_band4_gain);
708 #endif
710 return action;
712 void eq_hw_enable(bool enable)
714 #ifdef SIMULATOR
715 (void) enable;
716 #else
717 if (enable) {
718 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff,
719 0, global_settings.eq_hw_band0_gain);
720 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
721 global_settings.eq_hw_band1_bandwidth,
722 global_settings.eq_hw_band1_gain);
723 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
724 global_settings.eq_hw_band2_bandwidth,
725 global_settings.eq_hw_band2_gain);
726 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
727 global_settings.eq_hw_band3_bandwidth,
728 global_settings.eq_hw_band3_gain);
729 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff,
730 0, global_settings.eq_hw_band4_gain);
731 } else {
732 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff, 0, 0);
733 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
734 global_settings.eq_hw_band1_bandwidth, 0);
735 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
736 global_settings.eq_hw_band2_bandwidth, 0);
737 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
738 global_settings.eq_hw_band3_bandwidth, 0);
739 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff, 0, 0);
741 #endif
743 static int hweq_enable_callback(int action, const struct menu_item_ex *this_item)
745 (void)this_item;
746 if (action == ACTION_EXIT_MENUITEM)
748 eq_hw_enable(global_settings.eq_hw_enabled);
750 return action;
752 MENUITEM_SETTING(hw_eq_enable, &global_settings.eq_hw_enabled, hweq_enable_callback);
754 MENUITEM_SETTING(hw_eq_cutoff_0, &global_settings.eq_hw_band0_cutoff, band0_callback);
755 MENUITEM_SETTING(hw_eq_gain_0, &global_settings.eq_hw_band0_gain, band0_callback);
756 MAKE_MENU(hw_eq_band0, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), NULL, Icon_NOICON,
757 &hw_eq_cutoff_0, &hw_eq_gain_0);
759 MENUITEM_SETTING(hw_eq_cutoff_1, &global_settings.eq_hw_band1_center, band1_callback);
760 MENUITEM_SETTING(hw_eq_bandwidth_1, &global_settings.eq_hw_band1_bandwidth, band1_callback);
761 MENUITEM_SETTING(hw_eq_gain_1, &global_settings.eq_hw_band1_gain, band1_callback);
762 MAKE_MENU(hw_eq_band1, "Peak Filter 1", NULL, Icon_NOICON,
763 &hw_eq_cutoff_1, &hw_eq_bandwidth_1, &hw_eq_gain_1);
765 MENUITEM_SETTING(hw_eq_cutoff_2, &global_settings.eq_hw_band2_center, band2_callback);
766 MENUITEM_SETTING(hw_eq_bandwidth_2, &global_settings.eq_hw_band2_bandwidth, band2_callback);
767 MENUITEM_SETTING(hw_eq_gain_2, &global_settings.eq_hw_band2_gain, band2_callback);
768 MAKE_MENU(hw_eq_band2, "Peak Filter 2", NULL, Icon_NOICON,
769 &hw_eq_cutoff_2, &hw_eq_bandwidth_2, &hw_eq_gain_2);
771 MENUITEM_SETTING(hw_eq_cutoff_3, &global_settings.eq_hw_band3_center, band3_callback);
772 MENUITEM_SETTING(hw_eq_bandwidth_3, &global_settings.eq_hw_band3_bandwidth, band3_callback);
773 MENUITEM_SETTING(hw_eq_gain_3, &global_settings.eq_hw_band3_gain, band3_callback);
774 MAKE_MENU(hw_eq_band3, "Peak Filter 3", NULL, Icon_NOICON,
775 &hw_eq_cutoff_3, &hw_eq_bandwidth_3, &hw_eq_gain_3);
777 MENUITEM_SETTING(hw_eq_cutoff_4, &global_settings.eq_hw_band4_cutoff, band4_callback);
778 MENUITEM_SETTING(hw_eq_gain_4, &global_settings.eq_hw_band4_gain, band4_callback);
779 MAKE_MENU(hw_eq_band4, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL, Icon_NOICON,
780 &hw_eq_cutoff_4, &hw_eq_gain_4);
782 MAKE_MENU(hw_eq_menu, ID2P(LANG_EQUALIZER_HARDWARE), NULL, Icon_EQ,
783 &hw_eq_enable, &hw_eq_band0, &hw_eq_band1,
784 &hw_eq_band2, &hw_eq_band3, &hw_eq_band4);
787 #endif