Rework Display Options and File View.
[Rockbox.git] / apps / eq_menu.c
blob5dc554316c7babbe24876267bd9b45960906fe10
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 "button.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"
49 /* Key definitions */
50 #if (CONFIG_KEYPAD == IRIVER_H100_PAD || \
51 CONFIG_KEYPAD == IRIVER_H300_PAD)
53 #define EQ_BTN_MODIFIER BUTTON_ON
54 #define EQ_BTN_DECREMENT BUTTON_LEFT
55 #define EQ_BTN_INCREMENT BUTTON_RIGHT
56 #define EQ_BTN_NEXT_BAND BUTTON_DOWN
57 #define EQ_BTN_PREV_BAND BUTTON_UP
58 #define EQ_BTN_CHANGE_MODE BUTTON_SELECT
59 #define EQ_BTN_EXIT BUTTON_OFF
61 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
62 (CONFIG_KEYPAD == IPOD_3G_PAD)
64 #define EQ_BTN_DECREMENT BUTTON_SCROLL_BACK
65 #define EQ_BTN_INCREMENT BUTTON_SCROLL_FWD
66 #define EQ_BTN_NEXT_BAND BUTTON_RIGHT
67 #define EQ_BTN_PREV_BAND BUTTON_LEFT
68 #define EQ_BTN_CHANGE_MODE BUTTON_SELECT
69 #define EQ_BTN_EXIT BUTTON_MENU
71 #elif CONFIG_KEYPAD == IAUDIO_X5_PAD
73 #define EQ_BTN_DECREMENT BUTTON_LEFT
74 #define EQ_BTN_INCREMENT BUTTON_RIGHT
75 #define EQ_BTN_NEXT_BAND BUTTON_DOWN
76 #define EQ_BTN_PREV_BAND BUTTON_UP
77 #define EQ_BTN_CHANGE_MODE BUTTON_REC
78 #define EQ_BTN_EXIT BUTTON_SELECT
80 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
82 #define EQ_BTN_DECREMENT BUTTON_LEFT
83 #define EQ_BTN_INCREMENT BUTTON_RIGHT
84 #define EQ_BTN_NEXT_BAND BUTTON_DOWN
85 #define EQ_BTN_PREV_BAND BUTTON_UP
86 #define EQ_BTN_CHANGE_MODE BUTTON_SELECT
87 #define EQ_BTN_EXIT BUTTON_PLAY
89 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
91 #define EQ_BTN_DECREMENT BUTTON_LEFT
92 #define EQ_BTN_INCREMENT BUTTON_RIGHT
93 #define EQ_BTN_NEXT_BAND BUTTON_DOWN
94 #define EQ_BTN_PREV_BAND BUTTON_UP
95 #define EQ_BTN_CHANGE_MODE BUTTON_SELECT
96 #define EQ_BTN_EXIT BUTTON_A
98 #endif
100 /* Various user interface limits and sizes */
101 #define EQ_CUTOFF_MIN 20
102 #define EQ_CUTOFF_MAX 22040
103 #define EQ_CUTOFF_STEP 10
104 #define EQ_CUTOFF_FAST_STEP 100
105 #define EQ_GAIN_MIN (-240)
106 #define EQ_GAIN_MAX 240
107 #define EQ_GAIN_STEP 5
108 #define EQ_GAIN_FAST_STEP 10
109 #define EQ_Q_MIN 5
110 #define EQ_Q_MAX 64
111 #define EQ_Q_STEP 1
112 #define EQ_Q_FAST_STEP 10
114 #define EQ_USER_DIVISOR 10
117 * Utility functions
120 static void eq_gain_format(char* buffer, int buffer_size, int value, const char* unit)
122 int v = abs(value);
124 snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "",
125 v / EQ_USER_DIVISOR, v % EQ_USER_DIVISOR, unit);
128 static void eq_q_format(char* buffer, int buffer_size, int value, const char* unit)
130 snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
133 static void eq_precut_format(char* buffer, int buffer_size, int value, const char* unit)
135 snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
136 value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
140 * Settings functions
143 static bool eq_enabled(void)
145 int i;
147 bool result = set_bool(str(LANG_EQUALIZER_ENABLED),
148 &global_settings.eq_enabled);
150 dsp_set_eq(global_settings.eq_enabled);
152 dsp_set_eq_precut(global_settings.eq_precut);
154 /* Update all bands */
155 for(i = 0; i < 5; i++) {
156 dsp_set_eq_coefs(i);
159 return result;
162 static bool eq_precut(void)
164 bool result = set_int(str(LANG_EQUALIZER_PRECUT), str(LANG_UNIT_DB),
165 UNIT_DB, &global_settings.eq_precut, dsp_set_eq_precut, 5, 0, 240,
166 eq_precut_format);
168 return result;
171 /* Possibly dodgy way of simplifying the code a bit. */
172 #define eq_make_gain_label(buf, bufsize, frequency) snprintf((buf), \
173 (bufsize), str(LANG_EQUALIZER_GAIN_ITEM), (frequency))
175 #define eq_set_center(band) \
176 static bool eq_set_band ## band ## _center(void) \
178 bool result = set_int(str(LANG_EQUALIZER_BAND_CENTER), "Hertz", \
179 UNIT_HERTZ, &global_settings.eq_band ## band ## _cutoff, NULL, \
180 EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \
181 dsp_set_eq_coefs(band); \
182 return result; \
185 #define eq_set_cutoff(band) \
186 static bool eq_set_band ## band ## _cutoff(void) \
188 bool result = set_int(str(LANG_EQUALIZER_BAND_CUTOFF), "Hertz", \
189 UNIT_HERTZ, &global_settings.eq_band ## band ## _cutoff, NULL, \
190 EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \
191 dsp_set_eq_coefs(band); \
192 return result; \
195 #define eq_set_q(band) \
196 static bool eq_set_band ## band ## _q(void) \
198 bool result = set_int(str(LANG_EQUALIZER_BAND_Q), "Q", UNIT_INT, \
199 &global_settings.eq_band ## band ## _q, NULL, \
200 EQ_Q_STEP, EQ_Q_MIN, EQ_Q_MAX, eq_q_format); \
201 dsp_set_eq_coefs(band); \
202 return result; \
205 #define eq_set_gain(band) \
206 static bool eq_set_band ## band ## _gain(void) \
208 bool result = set_int("Band " #band, str(LANG_UNIT_DB), UNIT_DB, \
209 &global_settings.eq_band ## band ## _gain, NULL, \
210 EQ_GAIN_STEP, EQ_GAIN_MIN, EQ_GAIN_MAX, eq_gain_format); \
211 dsp_set_eq_coefs(band); \
212 return result; \
215 eq_set_cutoff(0);
216 eq_set_center(1);
217 eq_set_center(2);
218 eq_set_center(3);
219 eq_set_cutoff(4);
221 eq_set_q(0);
222 eq_set_q(1);
223 eq_set_q(2);
224 eq_set_q(3);
225 eq_set_q(4);
227 eq_set_gain(0);
228 eq_set_gain(1);
229 eq_set_gain(2);
230 eq_set_gain(3);
231 eq_set_gain(4);
233 static bool eq_gain_menu(void)
235 int m, i;
236 int *setting;
237 bool result;
238 char gain_label[5][32];
239 static struct menu_item items[5] = {
240 { NULL, eq_set_band0_gain },
241 { NULL, eq_set_band1_gain },
242 { NULL, eq_set_band2_gain },
243 { NULL, eq_set_band3_gain },
244 { NULL, eq_set_band4_gain },
247 setting = &global_settings.eq_band0_cutoff;
249 /* Construct menu labels */
250 for(i = 0; i < 5; i++) {
251 eq_make_gain_label(gain_label[i], sizeof(gain_label[i]),
252 *setting);
253 items[i].desc = gain_label[i];
255 /* Skip to next band */
256 setting += 3;
259 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
260 NULL, NULL, NULL);
261 result = menu_run(m);
262 menu_exit(m);
264 return result;
267 static bool eq_set_band0(void)
269 int m;
270 bool result;
271 static const struct menu_item items[] = {
272 { ID2P(LANG_EQUALIZER_BAND_CUTOFF), eq_set_band0_cutoff },
273 { ID2P(LANG_EQUALIZER_BAND_Q), eq_set_band0_q },
274 { ID2P(LANG_EQUALIZER_BAND_GAIN), eq_set_band0_gain },
277 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
278 NULL, NULL, NULL);
279 result = menu_run(m);
280 menu_exit(m);
282 return result;
285 static bool eq_set_band1(void)
287 int m;
288 bool result;
289 static const struct menu_item items[] = {
290 { ID2P(LANG_EQUALIZER_BAND_CENTER), eq_set_band1_center },
291 { ID2P(LANG_EQUALIZER_BAND_Q), eq_set_band1_q },
292 { ID2P(LANG_EQUALIZER_BAND_GAIN), eq_set_band1_gain },
295 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
296 NULL, NULL, NULL);
297 result = menu_run(m);
298 menu_exit(m);
300 return result;
303 static bool eq_set_band2(void)
305 int m;
306 bool result;
307 static const struct menu_item items[] = {
308 { ID2P(LANG_EQUALIZER_BAND_CENTER), eq_set_band2_center },
309 { ID2P(LANG_EQUALIZER_BAND_Q), eq_set_band2_q },
310 { ID2P(LANG_EQUALIZER_BAND_GAIN), eq_set_band2_gain },
313 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
314 NULL, NULL, NULL);
315 result = menu_run(m);
316 menu_exit(m);
318 return result;
321 static bool eq_set_band3(void)
323 int m;
324 bool result;
325 static const struct menu_item items[] = {
326 { ID2P(LANG_EQUALIZER_BAND_CENTER), eq_set_band3_center },
327 { ID2P(LANG_EQUALIZER_BAND_Q), eq_set_band3_q },
328 { ID2P(LANG_EQUALIZER_BAND_GAIN), eq_set_band3_gain },
331 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
332 NULL, NULL, NULL);
333 result = menu_run(m);
334 menu_exit(m);
336 return result;
339 static bool eq_set_band4(void)
341 int m;
342 bool result;
343 static const struct menu_item items[] = {
344 { ID2P(LANG_EQUALIZER_BAND_CUTOFF), eq_set_band4_cutoff },
345 { ID2P(LANG_EQUALIZER_BAND_Q), eq_set_band4_q },
346 { ID2P(LANG_EQUALIZER_BAND_GAIN), eq_set_band4_gain },
349 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
350 NULL, NULL, NULL);
351 result = menu_run(m);
352 menu_exit(m);
354 return result;
357 static bool eq_advanced_menu(void)
359 int m, i;
360 bool result;
361 char peak_band_label[3][32];
362 static struct menu_item items[] = {
363 { ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), eq_set_band0 },
364 { NULL, eq_set_band1 },
365 { NULL, eq_set_band2 },
366 { NULL, eq_set_band3 },
367 { ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), eq_set_band4 },
370 /* Construct menu labels */
371 for(i = 1; i < 4; i++) {
372 snprintf(peak_band_label[i-1], sizeof(peak_band_label[i-1]),
373 str(LANG_EQUALIZER_BAND_PEAK), i);
374 items[i].desc = peak_band_label[i-1];
377 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
378 NULL, NULL, NULL);
379 result = menu_run(m);
380 menu_exit(m);
382 return result;
385 enum eq_slider_mode {
386 GAIN,
387 CUTOFF,
391 enum eq_type {
392 LOW_SHELF,
393 PEAK,
394 HIGH_SHELF
397 /* Draw the UI for a whole EQ band */
398 static int draw_eq_slider(struct screen * screen, int x, int y,
399 int width, int cutoff, int q, int gain, bool selected,
400 enum eq_slider_mode mode, enum eq_type type)
402 char buf[26];
403 const char separator[2] = " ";
404 int steps, min_item, max_item;
405 int abs_gain = abs(gain);
406 int current_x, total_height, separator_width, separator_height;
407 int w, h;
408 const int slider_height = 6;
410 switch(mode) {
411 case Q:
412 steps = EQ_Q_MAX - EQ_Q_MIN;
413 min_item = q - EQ_Q_STEP - EQ_Q_MIN;
414 max_item = q + EQ_Q_STEP - EQ_Q_MIN;
415 break;
416 case CUTOFF:
417 steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN;
418 min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2;
419 max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2;
420 break;
421 case GAIN:
422 default:
423 steps = EQ_GAIN_MAX - EQ_GAIN_MIN;
424 min_item = abs(EQ_GAIN_MIN) + gain - EQ_GAIN_STEP * 5;
425 max_item = abs(EQ_GAIN_MIN) + gain + EQ_GAIN_STEP * 5;
426 break;
429 /* Start two pixels in, one for border, one for margin */
430 current_x = x + 2;
432 /* Figure out how large our separator string is */
433 screen->getstringsize(separator, &separator_width, &separator_height);
435 /* Total height includes margins, text, and line selector */
436 total_height = separator_height + slider_height + 2 + 3;
438 /* Print out the band label */
439 if (type == LOW_SHELF) {
440 screen->putsxy(current_x, y + 2, "LS:");
441 screen->getstringsize("LS:", &w, &h);
442 } else if (type == HIGH_SHELF) {
443 screen->putsxy(current_x, y + 2, "HS:");
444 screen->getstringsize("HS:", &w, &h);
445 } else {
446 screen->putsxy(current_x, y + 2, "PK:");
447 screen->getstringsize("PK:", &w, &h);
449 current_x += w;
451 /* Print separator */
452 screen->set_drawmode(DRMODE_SOLID);
453 screen->putsxy(current_x, y + 2, separator);
454 current_x += separator_width;
456 /* Print out gain part of status line */
457 snprintf(buf, sizeof(buf), "%s%2d.%ddB", gain < 0 ? "-" : " ",
458 abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR);
460 if (mode == GAIN && selected)
461 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
463 screen->putsxy(current_x, y + 2, buf);
464 screen->getstringsize(buf, &w, &h);
465 current_x += w;
467 /* Print separator */
468 screen->set_drawmode(DRMODE_SOLID);
469 screen->putsxy(current_x, y + 2, separator);
470 current_x += separator_width;
472 /* Print out cutoff part of status line */
473 snprintf(buf, sizeof(buf), "%5dHz", cutoff);
475 if (mode == CUTOFF && selected)
476 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
478 screen->putsxy(current_x, y + 2, buf);
479 screen->getstringsize(buf, &w, &h);
480 current_x += w;
482 /* Print separator */
483 screen->set_drawmode(DRMODE_SOLID);
484 screen->putsxy(current_x, y + 2, separator);
485 current_x += separator_width;
487 /* Print out Q part of status line */
488 snprintf(buf, sizeof(buf), "%d.%d Q", q / EQ_USER_DIVISOR,
489 q % EQ_USER_DIVISOR);
491 if (mode == Q && selected)
492 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
494 screen->putsxy(current_x, y + 2, buf);
495 screen->getstringsize(buf, &w, &h);
496 current_x += w;
498 screen->set_drawmode(DRMODE_SOLID);
500 /* Draw selection box */
501 if (selected) {
502 screen->drawrect(x, y, width, total_height);
505 /* Draw horizontal slider. Reuse scrollbar for this */
506 gui_scrollbar_draw(screen, x + 3, y + h + 3, width - 6, slider_height, steps,
507 min_item, max_item, HORIZONTAL);
509 return total_height;
512 /* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
513 static int draw_eq_sliders(int current_band, enum eq_slider_mode mode)
515 int i, gain, q, cutoff;
516 int height = 2; /* Two pixel margin */
517 int slider_width = screens[SCREEN_MAIN].width - 4; /* two pixel margin on each side */
518 int *setting = &global_settings.eq_band0_cutoff;
519 enum eq_type type;
521 for( i = 0; i < 5; ++i) {
522 cutoff = *setting++;
523 q = *setting++;
524 gain = *setting++;
526 if (i == 0) {
527 type = LOW_SHELF;
528 } else if (i == 4) {
529 type = HIGH_SHELF;
530 } else {
531 type = PEAK;
534 height += draw_eq_slider(&(screens[SCREEN_MAIN]), 2, height,
535 slider_width, cutoff, q, gain, i == current_band, mode, type);
537 /* add a margin */
538 height += 2;
541 return height;
544 /* Provides a graphical means of editing the EQ settings */
545 bool eq_menu_graphical(void)
547 bool exit_request = false;
548 bool result = true;
549 bool has_changed = false;
550 int button;
551 int *setting;
552 int current_band, y, step, fast_step, min, max, voice_unit;
553 enum eq_slider_mode mode;
554 enum eq_type current_type;
555 char buf[24];
557 screens[SCREEN_MAIN].setfont(FONT_SYSFIXED);
558 screens[SCREEN_MAIN].clear_display();
560 /* Start off editing gain on the first band */
561 mode = GAIN;
562 current_type = LOW_SHELF;
563 current_band = 0;
565 while (!exit_request) {
566 /* Clear the screen. The drawing routines expect this */
567 screens[SCREEN_MAIN].clear_display();
569 /* Draw equalizer band details */
570 y = draw_eq_sliders(current_band, mode);
572 /* Set pointer to the band data currently editable */
573 if (mode == GAIN) {
574 /* gain */
575 setting = &global_settings.eq_band0_gain;
576 setting += current_band * 3;
578 step = EQ_GAIN_STEP;
579 fast_step = EQ_GAIN_FAST_STEP;
580 min = EQ_GAIN_MIN;
581 max = EQ_GAIN_MAX;
582 voice_unit = UNIT_DB;
584 snprintf(buf, sizeof(buf), str(LANG_EQUALIZER_EDIT_MODE),
585 str(LANG_EQUALIZER_BAND_GAIN));
587 screens[SCREEN_MAIN].putsxy(2, y, buf);
588 } else if (mode == CUTOFF) {
589 /* cutoff */
590 setting = &global_settings.eq_band0_cutoff;
591 setting += current_band * 3;
593 step = EQ_CUTOFF_STEP;
594 fast_step = EQ_CUTOFF_FAST_STEP;
595 min = EQ_CUTOFF_MIN;
596 max = EQ_CUTOFF_MAX;
597 voice_unit = UNIT_HERTZ;
599 snprintf(buf, sizeof(buf), str(LANG_EQUALIZER_EDIT_MODE),
600 str(LANG_EQUALIZER_BAND_CUTOFF));
602 screens[SCREEN_MAIN].putsxy(2, y, buf);
603 } else {
604 /* Q */
605 setting = &global_settings.eq_band0_q;
606 setting += current_band * 3;
608 step = EQ_Q_STEP;
609 fast_step = EQ_Q_FAST_STEP;
610 min = EQ_Q_MIN;
611 max = EQ_Q_MAX;
612 voice_unit = UNIT_INT;
614 snprintf(buf, sizeof(buf), str(LANG_EQUALIZER_EDIT_MODE),
615 str(LANG_EQUALIZER_BAND_Q));
617 screens[SCREEN_MAIN].putsxy(2, y, buf);
620 screens[SCREEN_MAIN].update();
622 button = button_get(true);
624 switch (button) {
625 case EQ_BTN_DECREMENT:
626 case EQ_BTN_DECREMENT | BUTTON_REPEAT:
627 *(setting) -= step;
628 has_changed = true;
629 if (*(setting) < min)
630 *(setting) = min;
631 break;
633 case EQ_BTN_INCREMENT:
634 case EQ_BTN_INCREMENT | BUTTON_REPEAT:
635 *(setting) += step;
636 has_changed = true;
637 if (*(setting) > max)
638 *(setting) = max;
639 break;
641 #ifdef EQ_BTN_MODIFIER
642 case EQ_BTN_MODIFIER | EQ_BTN_INCREMENT:
643 case EQ_BTN_MODIFIER | EQ_BTN_INCREMENT | BUTTON_REPEAT:
644 *(setting) += fast_step;
645 has_changed = true;
646 if (*(setting) > max)
647 *(setting) = max;
648 break;
650 case EQ_BTN_MODIFIER | EQ_BTN_DECREMENT:
651 case EQ_BTN_MODIFIER | EQ_BTN_DECREMENT | BUTTON_REPEAT:
652 *(setting) -= fast_step;
653 has_changed = true;
654 if (*(setting) < min)
655 *(setting) = min;
656 break;
657 #endif
659 case EQ_BTN_PREV_BAND:
660 case EQ_BTN_PREV_BAND | BUTTON_REPEAT:
661 current_band--;
662 if (current_band < 0)
663 current_band = 4; /* wrap around */
664 break;
666 case EQ_BTN_NEXT_BAND:
667 case EQ_BTN_NEXT_BAND | BUTTON_REPEAT:
668 current_band++;
669 if (current_band > 4)
670 current_band = 0; /* wrap around */
671 break;
673 case EQ_BTN_CHANGE_MODE:
674 case EQ_BTN_CHANGE_MODE | BUTTON_REPEAT:
675 mode++;
676 if (mode > Q)
677 mode = GAIN; /* wrap around */
678 break;
680 case EQ_BTN_EXIT:
681 case EQ_BTN_EXIT | BUTTON_REPEAT:
682 exit_request = true;
683 result = false;
684 break;
686 default:
687 if(default_event_handler(button) == SYS_USB_CONNECTED) {
688 exit_request = true;
689 result = true;
691 break;
694 /* Update the filter if the user changed something */
695 if (has_changed) {
696 dsp_set_eq_coefs(current_band);
697 has_changed = false;
701 /* Reset screen settings */
702 screens[SCREEN_MAIN].setfont(FONT_UI);
703 screens[SCREEN_MAIN].clear_display();
705 return result;
708 /* Preset saver.
709 * TODO: Can the settings system be used to do this instead?
711 static bool eq_save_preset(void)
713 int fd, i;
714 char filename[MAX_PATH];
715 int *setting;
717 create_numbered_filename(filename, EQS_DIR, "eq", ".cfg", 2);
719 /* allow user to modify filename */
720 while (true) {
721 if (!kbd_input(filename, sizeof filename)) {
722 fd = creat(filename,0);
723 if (fd < 0)
724 gui_syncsplash(HZ, true, str(LANG_FAILED));
725 else
726 break;
728 else {
729 gui_syncsplash(HZ, true, str(LANG_MENU_SETTING_CANCEL));
730 return false;
734 /* TODO: Should we really do this? */
735 fdprintf(fd, "eq enabled: on\r\n");
736 fdprintf(fd, "eq precut: %d\r\n", global_settings.eq_precut);
738 setting = &global_settings.eq_band0_cutoff;
740 for(i = 0; i < 5; ++i) {
741 fdprintf(fd, "eq band %d cutoff: %d\r\n", i, *setting++);
742 fdprintf(fd, "eq band %d q: %d\r\n", i, *setting++);
743 fdprintf(fd, "eq band %d gain: %d\r\n", i, *setting++);
746 close(fd);
748 gui_syncsplash(HZ, true, str(LANG_SETTINGS_SAVED));
750 return true;
753 /* Allows browsing of preset files */
754 bool eq_browse_presets(void)
756 return rockbox_browse(EQS_DIR, SHOW_CFG);
759 /* Full equalizer menu */
760 bool eq_menu(void)
762 int m;
763 bool result;
764 static const struct menu_item items[] = {
765 { ID2P(LANG_EQUALIZER_ENABLED), eq_enabled },
766 { ID2P(LANG_EQUALIZER_GRAPHICAL), eq_menu_graphical },
767 { ID2P(LANG_EQUALIZER_PRECUT), eq_precut },
768 { ID2P(LANG_EQUALIZER_GAIN), eq_gain_menu },
769 { ID2P(LANG_EQUALIZER_ADVANCED), eq_advanced_menu },
770 { ID2P(LANG_EQUALIZER_SAVE), eq_save_preset },
771 { ID2P(LANG_EQUALIZER_BROWSE), eq_browse_presets },
774 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
775 NULL, NULL, NULL);
776 result = menu_run(m);
777 menu_exit(m);
779 return result;