1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Dan Everton
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
32 #include "mp3_playback.h"
43 #include "screen_access.h"
45 #include "gui/scrollbar.h"
46 #include "menu_common.h"
48 #include "exported_menus.h"
54 const char* eq_q_format(char* buffer
, size_t buffer_size
, int value
, const char* unit
)
56 snprintf(buffer
, buffer_size
, "%d.%d %s", value
/ EQ_USER_DIVISOR
,
57 value
% EQ_USER_DIVISOR
, unit
);
61 const char* eq_precut_format(char* buffer
, size_t buffer_size
, int value
, const char* unit
)
63 snprintf(buffer
, buffer_size
, "%s%d.%d %s", value
== 0 ? " " : "-",
64 value
/ EQ_USER_DIVISOR
, value
% EQ_USER_DIVISOR
, unit
);
71 static void eq_apply(void)
73 dsp_set_eq(global_settings
.eq_enabled
);
74 dsp_set_eq_precut(global_settings
.eq_precut
);
75 /* Update all bands */
76 for(int i
= 0; i
< 5; i
++) {
77 dsp_set_eq_coefs(i
, global_settings
.eq_band_settings
[i
].cutoff
,
78 global_settings
.eq_band_settings
[i
].q
,
79 global_settings
.eq_band_settings
[i
].gain
);
83 static int eq_setting_callback(int action
, const struct menu_item_ex
*this_item
)
87 case ACTION_ENTER_MENUITEM
:
88 action
= lowlatency_callback(action
, this_item
);
90 case ACTION_EXIT_MENUITEM
:
92 action
= lowlatency_callback(action
, this_item
);
98 MENUITEM_SETTING(eq_enable
, &global_settings
.eq_enabled
, eq_setting_callback
);
99 MENUITEM_SETTING(eq_precut
, &global_settings
.eq_precut
, eq_setting_callback
);
101 MENUITEM_SETTING(cutoff_0
, &global_settings
.eq_band_settings
[0].cutoff
,
102 eq_setting_callback
);
103 MENUITEM_SETTING(cutoff_1
, &global_settings
.eq_band_settings
[1].cutoff
,
104 eq_setting_callback
);
105 MENUITEM_SETTING(cutoff_2
, &global_settings
.eq_band_settings
[2].cutoff
,
106 eq_setting_callback
);
107 MENUITEM_SETTING(cutoff_3
, &global_settings
.eq_band_settings
[3].cutoff
,
108 eq_setting_callback
);
109 MENUITEM_SETTING(cutoff_4
, &global_settings
.eq_band_settings
[4].cutoff
,
110 eq_setting_callback
);
112 MENUITEM_SETTING(q_0
, &global_settings
.eq_band_settings
[0].q
,
113 eq_setting_callback
);
114 MENUITEM_SETTING(q_1
, &global_settings
.eq_band_settings
[1].q
,
115 eq_setting_callback
);
116 MENUITEM_SETTING(q_2
, &global_settings
.eq_band_settings
[2].q
,
117 eq_setting_callback
);
118 MENUITEM_SETTING(q_3
, &global_settings
.eq_band_settings
[3].q
,
119 eq_setting_callback
);
120 MENUITEM_SETTING(q_4
, &global_settings
.eq_band_settings
[4].q
,
121 eq_setting_callback
);
123 MENUITEM_SETTING(gain_0
, &global_settings
.eq_band_settings
[0].gain
,
124 eq_setting_callback
);
125 MENUITEM_SETTING(gain_1
, &global_settings
.eq_band_settings
[1].gain
,
126 eq_setting_callback
);
127 MENUITEM_SETTING(gain_2
, &global_settings
.eq_band_settings
[2].gain
,
128 eq_setting_callback
);
129 MENUITEM_SETTING(gain_3
, &global_settings
.eq_band_settings
[3].gain
,
130 eq_setting_callback
);
131 MENUITEM_SETTING(gain_4
, &global_settings
.eq_band_settings
[4].gain
,
132 eq_setting_callback
);
134 static char* gainitem_get_name(int selected_item
, void * data
, char *buffer
)
137 int *setting
= (int*)data
;
138 snprintf(buffer
, MAX_PATH
, str(LANG_EQUALIZER_GAIN_ITEM
), *setting
);
142 static int gainitem_speak_item(int selected_item
, void * data
)
145 int *setting
= (int*)data
;
146 talk_number(*setting
, false);
147 talk_id(LANG_EQUALIZER_GAIN_ITEM
, true);
151 static int do_option(void * param
)
153 const struct menu_item_ex
*setting
= (const struct menu_item_ex
*)param
;
154 lowlatency_callback(ACTION_ENTER_MENUITEM
, setting
);
155 do_setting_from_menu(setting
, NULL
);
157 lowlatency_callback(ACTION_EXIT_MENUITEM
, setting
);
161 MENUITEM_FUNCTION_DYNTEXT(gain_item_0
, MENU_FUNC_USEPARAM
,
162 do_option
, (void*)&gain_0
,
163 gainitem_get_name
, gainitem_speak_item
,
164 &global_settings
.eq_band_settings
[0].cutoff
,
166 MENUITEM_FUNCTION_DYNTEXT(gain_item_1
, MENU_FUNC_USEPARAM
,
167 do_option
, (void*)&gain_1
,
168 gainitem_get_name
, gainitem_speak_item
,
169 &global_settings
.eq_band_settings
[1].cutoff
,
171 MENUITEM_FUNCTION_DYNTEXT(gain_item_2
, MENU_FUNC_USEPARAM
,
172 do_option
, (void*)&gain_2
,
173 gainitem_get_name
, gainitem_speak_item
,
174 &global_settings
.eq_band_settings
[2].cutoff
,
176 MENUITEM_FUNCTION_DYNTEXT(gain_item_3
, MENU_FUNC_USEPARAM
,
177 do_option
, (void*)&gain_3
,
178 gainitem_get_name
, gainitem_speak_item
,
179 &global_settings
.eq_band_settings
[3].cutoff
,
181 MENUITEM_FUNCTION_DYNTEXT(gain_item_4
, MENU_FUNC_USEPARAM
,
182 do_option
, (void*)&gain_4
,
183 gainitem_get_name
, gainitem_speak_item
,
184 &global_settings
.eq_band_settings
[4].cutoff
,
187 MAKE_MENU(gain_menu
, ID2P(LANG_EQUALIZER_GAIN
), NULL
, Icon_NOICON
, &gain_item_0
,
188 &gain_item_1
, &gain_item_2
, &gain_item_3
, &gain_item_4
);
190 static const struct menu_item_ex
*band_items
[3][3] = {
191 { &cutoff_1
, &q_1
, &gain_1
},
192 { &cutoff_2
, &q_2
, &gain_2
},
193 { &cutoff_3
, &q_3
, &gain_3
}
196 static char* centerband_get_name(int selected_item
, void * data
, char *buffer
)
199 int band
= (intptr_t)data
;
200 snprintf(buffer
, MAX_PATH
, str(LANG_EQUALIZER_BAND_PEAK
), band
);
204 static int centerband_speak_item(int selected_item
, void * data
)
207 int band
= (intptr_t)data
;
208 talk_id(LANG_EQUALIZER_BAND_PEAK
, false);
209 talk_number(band
, true);
213 static int do_center_band_menu(void* param
)
215 int band
= (intptr_t)param
;
216 struct menu_item_ex menu
;
217 struct menu_callback_with_desc cb_and_desc
;
220 cb_and_desc
.menu_callback
= NULL
;
221 snprintf(desc
, MAX_PATH
, str(LANG_EQUALIZER_BAND_PEAK
), band
);
222 cb_and_desc
.desc
= desc
;
223 cb_and_desc
.icon_id
= Icon_EQ
;
224 menu
.flags
= MT_MENU
|(3<<MENU_COUNT_SHIFT
)|MENU_HAS_DESC
;
225 menu
.submenus
= band_items
[band
-1];
226 menu
.callback_and_desc
= &cb_and_desc
;
227 do_menu(&menu
, NULL
, NULL
, false);
231 MAKE_MENU(band_0_menu
, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF
), NULL
,
232 Icon_EQ
, &cutoff_0
, &q_0
, &gain_0
);
233 MENUITEM_FUNCTION_DYNTEXT(band_1_menu
, MENU_FUNC_USEPARAM
,
234 do_center_band_menu
, (void*)1,
235 centerband_get_name
, centerband_speak_item
,
236 (void*)1, NULL
, Icon_EQ
);
237 MENUITEM_FUNCTION_DYNTEXT(band_2_menu
, MENU_FUNC_USEPARAM
,
238 do_center_band_menu
, (void*)2,
239 centerband_get_name
, centerband_speak_item
,
240 (void*)2, NULL
, Icon_EQ
);
241 MENUITEM_FUNCTION_DYNTEXT(band_3_menu
, MENU_FUNC_USEPARAM
,
242 do_center_band_menu
, (void*)3,
243 centerband_get_name
, centerband_speak_item
,
244 (void*)3, NULL
, Icon_EQ
);
245 MAKE_MENU(band_4_menu
, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF
), NULL
,
246 Icon_EQ
, &cutoff_4
, &q_4
, &gain_4
);
248 MAKE_MENU(advanced_eq_menu_
, ID2P(LANG_EQUALIZER_ADVANCED
), NULL
, Icon_EQ
,
249 &band_0_menu
, &band_1_menu
, &band_2_menu
, &band_3_menu
, &band_4_menu
);
252 enum eq_slider_mode
{
264 /* Size of just the slider/srollbar */
265 #define SCROLLBAR_SIZE 6
267 /* Draw the UI for a whole EQ band */
268 static int draw_eq_slider(struct screen
* screen
, int x
, int y
,
269 int width
, int cutoff
, int q
, int gain
, bool selected
,
270 enum eq_slider_mode mode
, int band
)
273 int steps
, min_item
, max_item
;
274 int abs_gain
= abs(gain
);
275 int x1
, x2
, y1
, total_height
;
280 steps
= EQ_Q_MAX
- EQ_Q_MIN
;
281 min_item
= q
- EQ_Q_STEP
- EQ_Q_MIN
;
282 max_item
= q
+ EQ_Q_STEP
- EQ_Q_MIN
;
285 steps
= EQ_CUTOFF_MAX
- EQ_CUTOFF_MIN
;
286 min_item
= cutoff
- EQ_CUTOFF_FAST_STEP
* 2;
287 max_item
= cutoff
+ EQ_CUTOFF_FAST_STEP
* 2;
291 steps
= EQ_GAIN_MAX
- EQ_GAIN_MIN
;
292 min_item
= abs(EQ_GAIN_MIN
) + gain
- EQ_GAIN_STEP
* 5;
293 max_item
= abs(EQ_GAIN_MIN
) + gain
+ EQ_GAIN_STEP
* 5;
297 /* Start two pixels in, one for border, one for margin */
301 /* Print out the band label */
303 screen
->putsxy(x1
, y1
, "LS: ");
304 screen
->getstringsize("LS:", &w
, &h
);
305 } else if (band
== 4) {
306 screen
->putsxy(x1
, y1
, "HS: ");
307 screen
->getstringsize("HS:", &w
, &h
);
309 snprintf(buf
, sizeof(buf
), "PK%d:", band
);
310 screen
->putsxy(x1
, y1
, buf
);
311 screen
->getstringsize(buf
, &w
, &h
);
314 screen
->getstringsize("A", &w
, &h
);
315 x1
+= 5*w
; /* 4 chars for label + 1 space = 5 */
317 /* Print out gain part of status line (left justify after label) */
318 if (mode
== GAIN
&& selected
)
319 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
321 screen
->set_drawmode(DRMODE_SOLID
);
323 snprintf(buf
, sizeof(buf
), "%s%2d.%d%s", gain
< 0 ? "-" : " ",
324 abs_gain
/ EQ_USER_DIVISOR
, abs_gain
% EQ_USER_DIVISOR
,
325 screen
->lcdwidth
>= 160 ? "dB" : "");
326 screen
->putsxy(x1
, y1
, buf
);
327 screen
->getstringsize(buf
, &w
, &h
);
330 /* Print out Q part of status line (right justify) */
331 if (mode
== Q
&& selected
)
332 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
334 screen
->set_drawmode(DRMODE_SOLID
);
336 snprintf(buf
, sizeof(buf
), "%d.%d%s", q
/ EQ_USER_DIVISOR
,
337 q
% EQ_USER_DIVISOR
, screen
->lcdwidth
>= 160 ? " Q" : "");
338 screen
->getstringsize(buf
, &w
, &h
);
339 x2
= x
+ width
- w
- 2;
340 screen
->putsxy(x2
, y1
, buf
);
342 /* Print out cutoff part of status line (center between gain & Q) */
343 if (mode
== CUTOFF
&& selected
)
344 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
346 screen
->set_drawmode(DRMODE_SOLID
);
348 snprintf(buf
, sizeof(buf
), "%5d%s", cutoff
,
349 screen
->lcdwidth
>= 160 ? "Hz" : "");
350 screen
->getstringsize(buf
, &w
, &h
);
351 x1
= x1
+ (x2
- x1
- w
)/2;
352 screen
->putsxy(x1
, y1
, buf
);
354 /* Draw selection box */
355 total_height
= 3 + h
+ 1 + SCROLLBAR_SIZE
+ 3;
356 screen
->set_drawmode(DRMODE_SOLID
);
358 screen
->drawrect(x
, y
, width
, total_height
);
361 /* Draw horizontal slider. Reuse scrollbar for this */
362 gui_scrollbar_draw(screen
, x
+ 3, y1
+ h
+ 1, width
- 6, SCROLLBAR_SIZE
,
363 steps
, min_item
, max_item
, HORIZONTAL
);
368 /* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
369 static void draw_eq_sliders(struct screen
* screen
, int x
, int y
,
370 int nb_eq_sliders
, int start_item
,
371 int current_band
, enum eq_slider_mode mode
)
375 start_item
= MIN(start_item
, 5 - nb_eq_sliders
);
377 for (int i
= 0; i
< 5; i
++) {
378 struct eq_band_setting
*setting
= &global_settings
.eq_band_settings
[i
];
379 int cutoff
= setting
->cutoff
;
381 int gain
= setting
->gain
;
383 if (i
== start_item
+ nb_eq_sliders
)
386 if (i
>= start_item
) {
387 height
+= draw_eq_slider(screen
, x
, height
, screen
->lcdwidth
- x
- 1,
388 cutoff
, q
, gain
, i
== current_band
, mode
,
395 if (nb_eq_sliders
!= 5)
396 gui_scrollbar_draw(screen
, 0, y
, SCROLLBAR_SIZE
- 1,
397 screen
->lcdheight
- y
, 5,
398 start_item
, start_item
+ nb_eq_sliders
,
403 /* Provides a graphical means of editing the EQ settings */
404 bool eq_menu_graphical(void)
406 bool exit_request
= false;
408 bool has_changed
= false;
411 int current_band
, x
, y
, step
, fast_step
, min
, max
;
412 enum eq_slider_mode mode
;
414 int w
, h
, height
, start_item
, nb_eq_sliders
[NB_SCREENS
];
416 viewportmanager_theme_enable(i
, false, NULL
);
420 screens
[i
].set_viewport(NULL
);
421 screens
[i
].setfont(FONT_SYSFIXED
);
422 screens
[i
].clear_display();
424 /* Figure out how many sliders can be drawn on the screen */
425 screens
[i
].getstringsize("A", &w
, &h
);
427 /* Total height includes margins (1), text, slider, and line selector (1) */
428 height
= 3 + h
+ 1 + SCROLLBAR_SIZE
+ 3;
429 nb_eq_sliders
[i
] = screens
[i
].lcdheight
/ height
;
431 /* Make sure the "Edit Mode" text fits too */
432 height
= nb_eq_sliders
[i
]*height
+ h
+ 2;
433 if (height
> screens
[i
].lcdheight
)
436 if (nb_eq_sliders
[i
] > 5)
437 nb_eq_sliders
[i
] = 5;
442 /* Start off editing gain on the first band */
446 while (!exit_request
) {
449 screens
[i
].clear_display();
451 /* Set pointer to the band data currently editable */
454 setting
= &global_settings
.eq_band_settings
[current_band
].gain
;
457 fast_step
= EQ_GAIN_FAST_STEP
;
461 snprintf(buf
, sizeof(buf
), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE
),
462 str(LANG_SYSFONT_GAIN
), "(dB)");
464 screens
[i
].putsxy(0, 0, buf
);
465 } else if (mode
== CUTOFF
) {
467 setting
= &global_settings
.eq_band_settings
[current_band
].cutoff
;
469 step
= EQ_CUTOFF_STEP
;
470 fast_step
= EQ_CUTOFF_FAST_STEP
;
474 snprintf(buf
, sizeof(buf
), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE
),
475 str(LANG_SYSFONT_EQUALIZER_BAND_CUTOFF
), "(Hz)");
477 screens
[i
].putsxy(0, 0, buf
);
480 setting
= &global_settings
.eq_band_settings
[current_band
].q
;
483 fast_step
= EQ_Q_FAST_STEP
;
487 snprintf(buf
, sizeof(buf
), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE
),
488 str(LANG_EQUALIZER_BAND_Q
), "");
490 screens
[i
].putsxy(0, 0, buf
);
493 /* Draw scrollbar if needed */
494 if (nb_eq_sliders
[i
] != 5)
496 if (current_band
== 0) {
498 } else if (current_band
== 4) {
499 start_item
= 5 - nb_eq_sliders
[i
];
501 start_item
= current_band
- 1;
508 /* Draw equalizer band details */
509 draw_eq_sliders(&screens
[i
], x
, y
, nb_eq_sliders
[i
], start_item
,
515 button
= get_action(CONTEXT_SETTINGS_EQ
,TIMEOUT_BLOCK
);
518 case ACTION_SETTINGS_DEC
:
519 case ACTION_SETTINGS_DECREPEAT
:
522 if (*(setting
) < min
)
526 case ACTION_SETTINGS_INC
:
527 case ACTION_SETTINGS_INCREPEAT
:
530 if (*(setting
) > max
)
534 case ACTION_SETTINGS_INCBIGSTEP
:
535 *(setting
) += fast_step
;
537 if (*(setting
) > max
)
541 case ACTION_SETTINGS_DECBIGSTEP
:
542 *(setting
) -= fast_step
;
544 if (*(setting
) < min
)
548 case ACTION_STD_PREV
:
549 case ACTION_STD_PREVREPEAT
:
551 if (current_band
< 0)
552 current_band
= 4; /* wrap around */
555 case ACTION_STD_NEXT
:
556 case ACTION_STD_NEXTREPEAT
:
558 if (current_band
> 4)
559 current_band
= 0; /* wrap around */
565 mode
= GAIN
; /* wrap around */
568 case ACTION_STD_CANCEL
:
573 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
580 /* Update the filter if the user changed something */
582 dsp_set_eq_coefs(current_band
,
583 global_settings
.eq_band_settings
[current_band
].cutoff
,
584 global_settings
.eq_band_settings
[current_band
].q
,
585 global_settings
.eq_band_settings
[current_band
].gain
);
590 /* Reset screen settings */
593 screens
[i
].setfont(FONT_UI
);
594 screens
[i
].clear_display();
595 screens
[i
].set_viewport(NULL
);
596 viewportmanager_theme_undo(i
, false);
601 static bool eq_save_preset(void)
603 /* make sure that the eq is enabled for setting saving */
604 bool enabled
= global_settings
.eq_enabled
;
605 global_settings
.eq_enabled
= true;
607 bool result
= settings_save_config(SETTINGS_SAVE_EQPRESET
);
609 global_settings
.eq_enabled
= enabled
;
614 /* Allows browsing of preset files */
615 static struct browse_folder_info eqs
= { EQS_DIR
, SHOW_CFG
};
617 MENUITEM_FUNCTION(eq_graphical
, 0, ID2P(LANG_EQUALIZER_GRAPHICAL
),
618 (int(*)(void))eq_menu_graphical
, NULL
, lowlatency_callback
,
620 MENUITEM_FUNCTION(eq_save
, 0, ID2P(LANG_EQUALIZER_SAVE
),
621 (int(*)(void))eq_save_preset
, NULL
, NULL
, Icon_NOICON
);
622 MENUITEM_FUNCTION(eq_browse
, MENU_FUNC_USEPARAM
, ID2P(LANG_EQUALIZER_BROWSE
),
623 browse_folder
, (void*)&eqs
, lowlatency_callback
,
626 MAKE_MENU(equalizer_menu
, ID2P(LANG_EQUALIZER
), NULL
, Icon_EQ
,
627 &eq_enable
, &eq_graphical
, &eq_precut
, &gain_menu
,
628 &advanced_eq_menu_
, &eq_save
, &eq_browse
);