Revert "Replace yield_codec() with a call to queue_wait_w_tmo()" and the related...
[Rockbox.git] / apps / menus / eq_menu.c
blob4dd8c06c6507cc4b97501ed593ba63db23fbf555
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 void eq_apply(void)
83 int i;
84 dsp_set_eq(global_settings.eq_enabled);
85 dsp_set_eq_precut(global_settings.eq_precut);
86 /* Update all bands */
87 for(i = 0; i < 5; i++) {
88 dsp_set_eq_coefs(i);
91 int enable_callback(int action, const struct menu_item_ex *this_item)
93 (void)this_item;
94 if (action == ACTION_EXIT_MENUITEM)
95 eq_apply();
96 return action;
98 MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, enable_callback);
99 MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, enable_callback);
101 int dsp_set_coefs_callback(int action, const struct menu_item_ex *this_item)
103 (void)this_item;
104 if (action == ACTION_EXIT_MENUITEM)
106 /* for now, set every band... figure out a better way later */
107 int i=0;
108 for (i=0; i<5; i++)
109 dsp_set_eq_coefs(i);
111 return action;
114 char* gainitem_get_name(int selected_item, void * data, char *buffer)
116 (void)selected_item;
117 int *setting = (int*)data;
118 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_GAIN_ITEM), *setting);
119 return buffer;
121 int gainitem_speak_item(int selected_item, void * data)
123 (void)selected_item;
124 int *setting = (int*)data;
125 talk_number(*setting, false);
126 talk_id(LANG_EQUALIZER_GAIN_ITEM, true);
127 return 0;
130 int do_option(void* param)
132 const struct menu_item_ex *setting = (const struct menu_item_ex*)param;
133 do_setting_from_menu(setting);
134 eq_apply();
135 return 0;
138 MENUITEM_SETTING(cutoff_0, &global_settings.eq_band0_cutoff, dsp_set_coefs_callback);
139 MENUITEM_SETTING(cutoff_1, &global_settings.eq_band1_cutoff, dsp_set_coefs_callback);
140 MENUITEM_SETTING(cutoff_2, &global_settings.eq_band2_cutoff, dsp_set_coefs_callback);
141 MENUITEM_SETTING(cutoff_3, &global_settings.eq_band3_cutoff, dsp_set_coefs_callback);
142 MENUITEM_SETTING(cutoff_4, &global_settings.eq_band4_cutoff, dsp_set_coefs_callback);
144 MENUITEM_SETTING(q_0, &global_settings.eq_band0_q, dsp_set_coefs_callback);
145 MENUITEM_SETTING(q_1, &global_settings.eq_band1_q, dsp_set_coefs_callback);
146 MENUITEM_SETTING(q_2, &global_settings.eq_band2_q, dsp_set_coefs_callback);
147 MENUITEM_SETTING(q_3, &global_settings.eq_band3_q, dsp_set_coefs_callback);
148 MENUITEM_SETTING(q_4, &global_settings.eq_band4_q, dsp_set_coefs_callback);
150 MENUITEM_SETTING(gain_0, &global_settings.eq_band0_gain, dsp_set_coefs_callback);
151 MENUITEM_SETTING(gain_1, &global_settings.eq_band1_gain, dsp_set_coefs_callback);
152 MENUITEM_SETTING(gain_2, &global_settings.eq_band2_gain, dsp_set_coefs_callback);
153 MENUITEM_SETTING(gain_3, &global_settings.eq_band3_gain, dsp_set_coefs_callback);
154 MENUITEM_SETTING(gain_4, &global_settings.eq_band4_gain, dsp_set_coefs_callback);
156 MENUITEM_FUNCTION_DYNTEXT(gain_item_0, MENU_FUNC_USEPARAM,
157 do_option, (void*)&gain_0,
158 gainitem_get_name, gainitem_speak_item,
159 &global_settings.eq_band0_cutoff, NULL, Icon_NOICON);
160 MENUITEM_FUNCTION_DYNTEXT(gain_item_1, MENU_FUNC_USEPARAM,
161 do_option, (void*)&gain_1,
162 gainitem_get_name, gainitem_speak_item,
163 &global_settings.eq_band1_cutoff, NULL, Icon_NOICON);
164 MENUITEM_FUNCTION_DYNTEXT(gain_item_2, MENU_FUNC_USEPARAM,
165 do_option, (void*)&gain_2,
166 gainitem_get_name, gainitem_speak_item,
167 &global_settings.eq_band2_cutoff, NULL, Icon_NOICON);
168 MENUITEM_FUNCTION_DYNTEXT(gain_item_3, MENU_FUNC_USEPARAM,
169 do_option, (void*)&gain_3,
170 gainitem_get_name, gainitem_speak_item,
171 &global_settings.eq_band3_cutoff, NULL, Icon_NOICON);
172 MENUITEM_FUNCTION_DYNTEXT(gain_item_4, MENU_FUNC_USEPARAM,
173 do_option, (void*)&gain_4,
174 gainitem_get_name, gainitem_speak_item,
175 &global_settings.eq_band4_cutoff, NULL, Icon_NOICON);
177 MAKE_MENU(gain_menu, ID2P(LANG_EQUALIZER_GAIN), NULL, Icon_NOICON, &gain_item_0,
178 &gain_item_1, &gain_item_2, &gain_item_3, &gain_item_4);
180 static const struct menu_item_ex *band_items[3][3] = {
181 { &cutoff_1, &q_1, &gain_1 },
182 { &cutoff_2, &q_2, &gain_2 },
183 { &cutoff_3, &q_3, &gain_3 }
185 char* centerband_get_name(int selected_item, void * data, char *buffer)
187 (void)selected_item;
188 int band = (intptr_t)data;
189 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band);
190 return buffer;
192 int centerband_speak_item(int selected_item, void * data)
194 (void)selected_item;
195 int band = (intptr_t)data;
196 talk_id(LANG_EQUALIZER_BAND_PEAK, false);
197 talk_number(band, true);
198 return 0;
200 int do_center_band_menu(void* param)
202 int band = (intptr_t)param;
203 struct menu_item_ex menu;
204 struct menu_callback_with_desc cb_and_desc;
205 char desc[MAX_PATH];
207 cb_and_desc.menu_callback = NULL;
208 snprintf(desc, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band);
209 cb_and_desc.desc = desc;
210 cb_and_desc.icon_id = Icon_EQ;
211 menu.flags = MT_MENU|(3<<MENU_COUNT_SHIFT)|MENU_HAS_DESC;
212 menu.submenus = band_items[band-1];
213 menu.callback_and_desc = &cb_and_desc;
214 do_menu(&menu, NULL);
215 return 0;
217 MAKE_MENU(band_0_menu, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), NULL,
218 Icon_EQ, &cutoff_0, &q_0, &gain_0);
219 MENUITEM_FUNCTION_DYNTEXT(band_1_menu, MENU_FUNC_USEPARAM,
220 do_center_band_menu, (void*)1,
221 centerband_get_name, centerband_speak_item,
222 (void*)1, NULL, Icon_EQ);
223 MENUITEM_FUNCTION_DYNTEXT(band_2_menu, MENU_FUNC_USEPARAM,
224 do_center_band_menu, (void*)2,
225 centerband_get_name, centerband_speak_item,
226 (void*)2, NULL, Icon_EQ);
227 MENUITEM_FUNCTION_DYNTEXT(band_3_menu, MENU_FUNC_USEPARAM,
228 do_center_band_menu, (void*)3,
229 centerband_get_name, centerband_speak_item,
230 (void*)3, NULL, Icon_EQ);
231 MAKE_MENU(band_4_menu, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL,
232 Icon_EQ, &cutoff_4, &q_4, &gain_4);
234 MAKE_MENU(advanced_eq_menu_, ID2P(LANG_EQUALIZER_ADVANCED), NULL, Icon_EQ,
235 &band_0_menu, &band_1_menu, &band_2_menu, &band_3_menu, &band_4_menu);
238 enum eq_slider_mode {
239 GAIN,
240 CUTOFF,
244 enum eq_type {
245 LOW_SHELF,
246 PEAK,
247 HIGH_SHELF
250 /* Draw the UI for a whole EQ band */
251 static int draw_eq_slider(struct screen * screen, int x, int y,
252 int width, int cutoff, int q, int gain, bool selected,
253 enum eq_slider_mode mode, enum eq_type type)
255 char buf[26];
256 const char separator[2] = " ";
257 int steps, min_item, max_item;
258 int abs_gain = abs(gain);
259 int current_x, total_height, separator_width, separator_height;
260 int w, h;
261 const int slider_height = 6;
263 switch(mode) {
264 case Q:
265 steps = EQ_Q_MAX - EQ_Q_MIN;
266 min_item = q - EQ_Q_STEP - EQ_Q_MIN;
267 max_item = q + EQ_Q_STEP - EQ_Q_MIN;
268 break;
269 case CUTOFF:
270 steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN;
271 min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2;
272 max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2;
273 break;
274 case GAIN:
275 default:
276 steps = EQ_GAIN_MAX - EQ_GAIN_MIN;
277 min_item = abs(EQ_GAIN_MIN) + gain - EQ_GAIN_STEP * 5;
278 max_item = abs(EQ_GAIN_MIN) + gain + EQ_GAIN_STEP * 5;
279 break;
282 /* Start two pixels in, one for border, one for margin */
283 current_x = x + 2;
285 /* Figure out how large our separator string is */
286 screen->getstringsize(separator, &separator_width, &separator_height);
288 /* Total height includes margins, text, and line selector */
289 total_height = separator_height + slider_height + 2 + 3;
291 /* Print out the band label */
292 if (type == LOW_SHELF) {
293 screen->putsxy(current_x, y + 2, "LS:");
294 screen->getstringsize("LS:", &w, &h);
295 } else if (type == HIGH_SHELF) {
296 screen->putsxy(current_x, y + 2, "HS:");
297 screen->getstringsize("HS:", &w, &h);
298 } else {
299 screen->putsxy(current_x, y + 2, "PK:");
300 screen->getstringsize("PK:", &w, &h);
302 current_x += w;
304 /* Print separator */
305 screen->set_drawmode(DRMODE_SOLID);
306 screen->putsxy(current_x, y + 2, separator);
307 current_x += separator_width;
308 #if NB_SCREENS > 1
309 if (screen->screen_type == SCREEN_REMOTE) {
310 if (mode == GAIN) {
311 screen->putsxy(current_x, y + 2, str(LANG_GAIN));
312 screen->getstringsize(str(LANG_GAIN), &w, &h);
313 } else if (mode == CUTOFF) {
314 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_CUTOFF));
315 screen->getstringsize(str(LANG_EQUALIZER_BAND_CUTOFF), &w, &h);
316 } else {
317 screen->putsxy(current_x, y + 2, str(LANG_EQUALIZER_BAND_Q));
318 screen->getstringsize(str(LANG_EQUALIZER_BAND_Q), &w, &h);
321 /* Draw horizontal slider. Reuse scrollbar for this */
322 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
323 min_item, max_item, HORIZONTAL);
325 /* Print out cutoff part */
326 snprintf(buf, sizeof(buf), "%sGain %s%2d.%ddB",mode==GAIN?" > ":" ", gain < 0 ? "-" : " ",
327 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
328 screen->getstringsize(buf, &w, &h);
329 y = 3*h;
330 screen->putsxy(0, y, buf);
331 /* Print out cutoff part */
332 snprintf(buf, sizeof(buf), "%sCutoff %5dHz",mode==CUTOFF?" > ":" ", cutoff);
333 y += h;
334 screen->putsxy(0, y, buf);
335 snprintf(buf, sizeof(buf), "%sQ setting %d.%d Q",mode==Q?" > ":" ", q / EQ_USER_DIVISOR,
336 q % EQ_USER_DIVISOR);
337 y += h;
338 screen->putsxy(0, y, buf);
339 return y;
341 #endif
343 /* Print out gain part of status line */
344 snprintf(buf, sizeof(buf), "%s%2d.%ddB", gain < 0 ? "-" : " ",
345 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
347 if (mode == GAIN && selected)
348 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
350 screen->putsxy(current_x, y + 2, buf);
351 screen->getstringsize(buf, &w, &h);
352 current_x += w;
354 /* Print separator */
355 screen->set_drawmode(DRMODE_SOLID);
356 screen->putsxy(current_x, y + 2, separator);
357 current_x += separator_width;
359 /* Print out cutoff part of status line */
360 snprintf(buf, sizeof(buf), "%5dHz", cutoff);
362 if (mode == CUTOFF && selected)
363 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
365 screen->putsxy(current_x, y + 2, buf);
366 screen->getstringsize(buf, &w, &h);
367 current_x += w;
369 /* Print separator */
370 screen->set_drawmode(DRMODE_SOLID);
371 screen->putsxy(current_x, y + 2, separator);
372 current_x += separator_width;
374 /* Print out Q part of status line */
375 snprintf(buf, sizeof(buf), "%d.%d Q", q / EQ_USER_DIVISOR,
376 q % EQ_USER_DIVISOR);
378 if (mode == Q && selected)
379 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
381 screen->putsxy(current_x, y + 2, buf);
382 screen->getstringsize(buf, &w, &h);
383 current_x += w;
385 screen->set_drawmode(DRMODE_SOLID);
387 /* Draw selection box */
388 if (selected) {
389 screen->drawrect(x, y, width, total_height);
392 /* Draw horizontal slider. Reuse scrollbar for this */
393 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
394 min_item, max_item, HORIZONTAL);
396 return total_height;
399 /* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
400 static int draw_eq_sliders(int current_band, enum eq_slider_mode mode)
402 int i, gain, q, cutoff;
403 int height = 2; /* Two pixel margin */
404 int slider_width[NB_SCREENS];
405 int *setting = &global_settings.eq_band0_cutoff;
406 enum eq_type type;
408 FOR_NB_SCREENS(i)
409 slider_width[i] = screens[i].width - 4; /* two pixel margin on each side */
411 for (i=0; i<5; i++) {
412 cutoff = *setting++;
413 q = *setting++;
414 gain = *setting++;
416 if (i == 0) {
417 type = LOW_SHELF;
418 } else if (i == 4) {
419 type = HIGH_SHELF;
420 } else {
421 type = PEAK;
423 height += draw_eq_slider(&(screens[SCREEN_MAIN]), 2, height,
424 slider_width[SCREEN_MAIN], cutoff, q, gain,
425 i == current_band, mode, type);
426 #if NB_SCREENS > 1
427 if (i == current_band)
428 draw_eq_slider(&(screens[SCREEN_REMOTE]), 2, 0,
429 slider_width[SCREEN_REMOTE], cutoff, q, gain,1, mode, type);
430 #endif
431 /* add a margin */
432 height += 2;
435 return height;
438 /* Provides a graphical means of editing the EQ settings */
439 bool eq_menu_graphical(void)
441 bool exit_request = false;
442 bool result = true;
443 bool has_changed = false;
444 int button;
445 int *setting;
446 int current_band, y, step, fast_step, min, max, voice_unit;
447 enum eq_slider_mode mode;
448 enum eq_type current_type;
449 char buf[24];
450 int i;
452 FOR_NB_SCREENS(i) {
453 screens[i].setfont(FONT_SYSFIXED);
454 screens[i].clear_display();
457 /* Start off editing gain on the first band */
458 mode = GAIN;
459 current_type = LOW_SHELF;
460 current_band = 0;
462 while (!exit_request) {
464 FOR_NB_SCREENS(i) {
465 /* Clear the screen. The drawing routines expect this */
466 screens[i].clear_display();
467 /* Draw equalizer band details */
468 y = draw_eq_sliders(current_band, mode);
471 /* Set pointer to the band data currently editable */
472 if (mode == GAIN) {
473 /* gain */
474 setting = &global_settings.eq_band0_gain;
475 setting += current_band * 3;
477 step = EQ_GAIN_STEP;
478 fast_step = EQ_GAIN_FAST_STEP;
479 min = EQ_GAIN_MIN;
480 max = EQ_GAIN_MAX;
481 voice_unit = UNIT_DB;
483 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
484 str(LANG_SYSFONT_GAIN));
486 screens[SCREEN_MAIN].putsxy(2, y, buf);
487 } else if (mode == CUTOFF) {
488 /* cutoff */
489 setting = &global_settings.eq_band0_cutoff;
490 setting += current_band * 3;
492 step = EQ_CUTOFF_STEP;
493 fast_step = EQ_CUTOFF_FAST_STEP;
494 min = EQ_CUTOFF_MIN;
495 max = EQ_CUTOFF_MAX;
496 voice_unit = UNIT_HERTZ;
498 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
499 str(LANG_SYSFONT_EQUALIZER_BAND_CUTOFF));
501 screens[SCREEN_MAIN].putsxy(2, y, buf);
502 } else {
503 /* Q */
504 setting = &global_settings.eq_band0_q;
505 setting += current_band * 3;
507 step = EQ_Q_STEP;
508 fast_step = EQ_Q_FAST_STEP;
509 min = EQ_Q_MIN;
510 max = EQ_Q_MAX;
511 voice_unit = UNIT_INT;
513 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
514 str(LANG_EQUALIZER_BAND_Q));
516 screens[SCREEN_MAIN].putsxy(2, y, buf);
519 FOR_NB_SCREENS(i) {
520 screens[i].update();
523 button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK);
525 switch (button) {
526 case ACTION_SETTINGS_DEC:
527 case ACTION_SETTINGS_DECREPEAT:
528 *(setting) -= step;
529 has_changed = true;
530 if (*(setting) < min)
531 *(setting) = min;
532 break;
534 case ACTION_SETTINGS_INC:
535 case ACTION_SETTINGS_INCREPEAT:
536 *(setting) += step;
537 has_changed = true;
538 if (*(setting) > max)
539 *(setting) = max;
540 break;
542 case ACTION_SETTINGS_INCBIGSTEP:
543 *(setting) += fast_step;
544 has_changed = true;
545 if (*(setting) > max)
546 *(setting) = max;
547 break;
549 case ACTION_SETTINGS_DECBIGSTEP:
550 *(setting) -= fast_step;
551 has_changed = true;
552 if (*(setting) < min)
553 *(setting) = min;
554 break;
556 case ACTION_STD_PREV:
557 case ACTION_STD_PREVREPEAT:
558 current_band--;
559 if (current_band < 0)
560 current_band = 4; /* wrap around */
561 break;
563 case ACTION_STD_NEXT:
564 case ACTION_STD_NEXTREPEAT:
565 current_band++;
566 if (current_band > 4)
567 current_band = 0; /* wrap around */
568 break;
570 case ACTION_STD_OK:
571 mode++;
572 if (mode > Q)
573 mode = GAIN; /* wrap around */
574 break;
576 case ACTION_STD_CANCEL:
577 exit_request = true;
578 result = false;
579 break;
581 default:
582 if(default_event_handler(button) == SYS_USB_CONNECTED) {
583 exit_request = true;
584 result = true;
586 break;
589 /* Update the filter if the user changed something */
590 if (has_changed) {
591 dsp_set_eq_coefs(current_band);
592 has_changed = false;
596 /* Reset screen settings */
597 FOR_NB_SCREENS(i) {
598 screens[i].setfont(FONT_UI);
599 screens[i].clear_display();
601 return result;
604 /* Preset saver.
605 * TODO: Can the settings system be used to do this instead?
607 static bool eq_save_preset(void)
609 int fd, i;
610 char filename[MAX_PATH];
611 int *setting;
613 create_numbered_filename(filename, EQS_DIR, "eq", ".cfg", 2
614 IF_CNFN_NUM_(, NULL));
616 /* allow user to modify filename */
617 while (true) {
618 if (!kbd_input(filename, sizeof filename)) {
619 fd = creat(filename);
620 if (fd < 0)
621 gui_syncsplash(HZ, ID2P(LANG_FAILED));
622 else
623 break;
625 else {
626 gui_syncsplash(HZ, ID2P(LANG_CANCEL));
627 return false;
631 /* TODO: Should we really do this? */
632 fdprintf(fd, "eq enabled: on\r\n");
633 fdprintf(fd, "eq precut: %d\r\n", global_settings.eq_precut);
635 setting = &global_settings.eq_band0_cutoff;
637 for(i = 0; i < 5; ++i) {
638 fdprintf(fd, "eq band %d cutoff: %d\r\n", i, *setting++);
639 fdprintf(fd, "eq band %d q: %d\r\n", i, *setting++);
640 fdprintf(fd, "eq band %d gain: %d\r\n", i, *setting++);
643 close(fd);
645 gui_syncsplash(HZ, ID2P(LANG_SETTINGS_SAVED));
647 return true;
650 /* Allows browsing of preset files */
651 bool eq_browse_presets(void)
653 return rockbox_browse(EQS_DIR, SHOW_CFG);
657 MENUITEM_FUNCTION(eq_graphical, 0, ID2P(LANG_EQUALIZER_GRAPHICAL),
658 (int(*)(void))eq_menu_graphical, NULL, NULL,
659 Icon_EQ);
660 MENUITEM_FUNCTION(eq_save, 0, ID2P(LANG_EQUALIZER_SAVE),
661 (int(*)(void))eq_save_preset, NULL, NULL, Icon_NOICON);
662 MENUITEM_FUNCTION(eq_browse, 0, ID2P(LANG_EQUALIZER_BROWSE),
663 (int(*)(void))eq_browse_presets, NULL, NULL, Icon_NOICON);
665 int soundmenu_callback(int action,const struct menu_item_ex *this_item);
666 MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), soundmenu_callback, Icon_EQ,
667 &eq_enable, &eq_graphical, &eq_precut, &gain_menu,
668 &advanced_eq_menu_, &eq_save, &eq_browse);
671 #ifdef HAVE_WM8758
673 void eq_hw_gain_format(char* buffer, size_t buffer_size, int value,
674 const char* unit)
676 snprintf(buffer, buffer_size, "%d %s", value, unit);
679 static int band0_callback(int action, const struct menu_item_ex *this_item)
681 (void)this_item;
682 if (action == ACTION_EXIT_MENUITEM)
684 #ifndef SIMULATOR
685 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff, 0,
686 global_settings.eq_hw_band0_gain);
687 #endif
689 return action;
691 static int band1_callback(int action, const struct menu_item_ex *this_item)
693 (void)this_item;
694 if (action == ACTION_EXIT_MENUITEM)
696 #ifndef SIMULATOR
697 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
698 global_settings.eq_hw_band1_bandwidth,
699 global_settings.eq_hw_band1_gain);
700 #endif
702 return action;
704 static int band2_callback(int action, const struct menu_item_ex *this_item)
706 (void)this_item;
707 if (action == ACTION_EXIT_MENUITEM)
709 #ifndef SIMULATOR
710 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
711 global_settings.eq_hw_band2_bandwidth,
712 global_settings.eq_hw_band2_gain);
713 #endif
715 return action;
717 static int band3_callback(int action, const struct menu_item_ex *this_item)
719 (void)this_item;
720 if (action == ACTION_EXIT_MENUITEM)
722 #ifndef SIMULATOR
723 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
724 global_settings.eq_hw_band3_bandwidth,
725 global_settings.eq_hw_band3_gain);
726 #endif
728 return action;
730 static int band4_callback(int action, const struct menu_item_ex *this_item)
732 (void)this_item;
733 if (action == ACTION_EXIT_MENUITEM)
735 #ifndef SIMULATOR
736 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff, 0,
737 global_settings.eq_hw_band4_gain);
738 #endif
740 return action;
742 void eq_hw_enable(bool enable)
744 #ifdef SIMULATOR
745 (void) enable;
746 #else
747 if (enable) {
748 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff,
749 0, global_settings.eq_hw_band0_gain);
750 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
751 global_settings.eq_hw_band1_bandwidth,
752 global_settings.eq_hw_band1_gain);
753 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
754 global_settings.eq_hw_band2_bandwidth,
755 global_settings.eq_hw_band2_gain);
756 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
757 global_settings.eq_hw_band3_bandwidth,
758 global_settings.eq_hw_band3_gain);
759 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff,
760 0, global_settings.eq_hw_band4_gain);
761 } else {
762 audiohw_set_equalizer_band(0, global_settings.eq_hw_band0_cutoff, 0, 0);
763 audiohw_set_equalizer_band(1, global_settings.eq_hw_band1_center,
764 global_settings.eq_hw_band1_bandwidth, 0);
765 audiohw_set_equalizer_band(2, global_settings.eq_hw_band2_center,
766 global_settings.eq_hw_band2_bandwidth, 0);
767 audiohw_set_equalizer_band(3, global_settings.eq_hw_band3_center,
768 global_settings.eq_hw_band3_bandwidth, 0);
769 audiohw_set_equalizer_band(4, global_settings.eq_hw_band4_cutoff, 0, 0);
771 #endif
773 static int hweq_enable_callback(int action, const struct menu_item_ex *this_item)
775 (void)this_item;
776 if (action == ACTION_EXIT_MENUITEM)
778 eq_hw_enable(global_settings.eq_hw_enabled);
780 return action;
782 MENUITEM_SETTING(hw_eq_enable, &global_settings.eq_hw_enabled, hweq_enable_callback);
784 MENUITEM_SETTING(hw_eq_cutoff_0, &global_settings.eq_hw_band0_cutoff, band0_callback);
785 MENUITEM_SETTING(hw_eq_gain_0, &global_settings.eq_hw_band0_gain, band0_callback);
786 MAKE_MENU(hw_eq_band0, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), NULL, Icon_NOICON,
787 &hw_eq_cutoff_0, &hw_eq_gain_0);
789 MENUITEM_SETTING(hw_eq_cutoff_1, &global_settings.eq_hw_band1_center, band1_callback);
790 MENUITEM_SETTING(hw_eq_bandwidth_1, &global_settings.eq_hw_band1_bandwidth, band1_callback);
791 MENUITEM_SETTING(hw_eq_gain_1, &global_settings.eq_hw_band1_gain, band1_callback);
792 MAKE_MENU(hw_eq_band1, "Peak Filter 1", NULL, Icon_NOICON,
793 &hw_eq_cutoff_1, &hw_eq_bandwidth_1, &hw_eq_gain_1);
795 MENUITEM_SETTING(hw_eq_cutoff_2, &global_settings.eq_hw_band2_center, band2_callback);
796 MENUITEM_SETTING(hw_eq_bandwidth_2, &global_settings.eq_hw_band2_bandwidth, band2_callback);
797 MENUITEM_SETTING(hw_eq_gain_2, &global_settings.eq_hw_band2_gain, band2_callback);
798 MAKE_MENU(hw_eq_band2, "Peak Filter 2", NULL, Icon_NOICON,
799 &hw_eq_cutoff_2, &hw_eq_bandwidth_2, &hw_eq_gain_2);
801 MENUITEM_SETTING(hw_eq_cutoff_3, &global_settings.eq_hw_band3_center, band3_callback);
802 MENUITEM_SETTING(hw_eq_bandwidth_3, &global_settings.eq_hw_band3_bandwidth, band3_callback);
803 MENUITEM_SETTING(hw_eq_gain_3, &global_settings.eq_hw_band3_gain, band3_callback);
804 MAKE_MENU(hw_eq_band3, "Peak Filter 3", NULL, Icon_NOICON,
805 &hw_eq_cutoff_3, &hw_eq_bandwidth_3, &hw_eq_gain_3);
807 MENUITEM_SETTING(hw_eq_cutoff_4, &global_settings.eq_hw_band4_cutoff, band4_callback);
808 MENUITEM_SETTING(hw_eq_gain_4, &global_settings.eq_hw_band4_gain, band4_callback);
809 MAKE_MENU(hw_eq_band4, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL, Icon_NOICON,
810 &hw_eq_cutoff_4, &hw_eq_gain_4);
812 MAKE_MENU(hw_eq_menu, ID2P(LANG_EQUALIZER_HARDWARE), NULL, Icon_EQ,
813 &hw_eq_enable, &hw_eq_band0, &hw_eq_band1,
814 &hw_eq_band2, &hw_eq_band3, &hw_eq_band4);
817 #endif