1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
30 #include "mp3_playback.h"
32 #include "statusbar.h"
45 #include "screen_access.h"
47 #include "gui/scrollbar.h"
49 #include "menu_common.h"
55 void eq_q_format(char* buffer
, size_t buffer_size
, int value
, const char* unit
)
57 snprintf(buffer
, buffer_size
, "%d.%d %s", value
/ EQ_USER_DIVISOR
, value
% EQ_USER_DIVISOR
, unit
);
60 void eq_precut_format(char* buffer
, size_t buffer_size
, int value
, const char* unit
)
62 snprintf(buffer
, buffer_size
, "%s%d.%d %s", value
== 0 ? " " : "-",
63 value
/ EQ_USER_DIVISOR
, value
% EQ_USER_DIVISOR
, unit
);
69 static void eq_apply(void)
72 dsp_set_eq(global_settings
.eq_enabled
);
73 dsp_set_eq_precut(global_settings
.eq_precut
);
74 /* Update all bands */
75 for(i
= 0; i
< 5; i
++) {
80 static int eq_setting_callback(int action
, const struct menu_item_ex
*this_item
)
84 case ACTION_ENTER_MENUITEM
:
85 action
= lowlatency_callback(action
, this_item
);
87 case ACTION_EXIT_MENUITEM
:
89 action
= lowlatency_callback(action
, this_item
);
95 MENUITEM_SETTING(eq_enable
, &global_settings
.eq_enabled
, eq_setting_callback
);
96 MENUITEM_SETTING(eq_precut
, &global_settings
.eq_precut
, eq_setting_callback
);
98 MENUITEM_SETTING(cutoff_0
, &global_settings
.eq_band0_cutoff
, eq_setting_callback
);
99 MENUITEM_SETTING(cutoff_1
, &global_settings
.eq_band1_cutoff
, eq_setting_callback
);
100 MENUITEM_SETTING(cutoff_2
, &global_settings
.eq_band2_cutoff
, eq_setting_callback
);
101 MENUITEM_SETTING(cutoff_3
, &global_settings
.eq_band3_cutoff
, eq_setting_callback
);
102 MENUITEM_SETTING(cutoff_4
, &global_settings
.eq_band4_cutoff
, eq_setting_callback
);
104 MENUITEM_SETTING(q_0
, &global_settings
.eq_band0_q
, eq_setting_callback
);
105 MENUITEM_SETTING(q_1
, &global_settings
.eq_band1_q
, eq_setting_callback
);
106 MENUITEM_SETTING(q_2
, &global_settings
.eq_band2_q
, eq_setting_callback
);
107 MENUITEM_SETTING(q_3
, &global_settings
.eq_band3_q
, eq_setting_callback
);
108 MENUITEM_SETTING(q_4
, &global_settings
.eq_band4_q
, eq_setting_callback
);
110 MENUITEM_SETTING(gain_0
, &global_settings
.eq_band0_gain
, eq_setting_callback
);
111 MENUITEM_SETTING(gain_1
, &global_settings
.eq_band1_gain
, eq_setting_callback
);
112 MENUITEM_SETTING(gain_2
, &global_settings
.eq_band2_gain
, eq_setting_callback
);
113 MENUITEM_SETTING(gain_3
, &global_settings
.eq_band3_gain
, eq_setting_callback
);
114 MENUITEM_SETTING(gain_4
, &global_settings
.eq_band4_gain
, eq_setting_callback
);
116 static char* gainitem_get_name(int selected_item
, void * data
, char *buffer
)
119 int *setting
= (int*)data
;
120 snprintf(buffer
, MAX_PATH
, str(LANG_EQUALIZER_GAIN_ITEM
), *setting
);
124 static int gainitem_speak_item(int selected_item
, void * data
)
127 int *setting
= (int*)data
;
128 talk_number(*setting
, false);
129 talk_id(LANG_EQUALIZER_GAIN_ITEM
, true);
133 static int do_option(void * param
)
135 const struct menu_item_ex
*setting
= (const struct menu_item_ex
*)param
;
136 lowlatency_callback(ACTION_ENTER_MENUITEM
, setting
);
137 do_setting_from_menu(setting
, NULL
);
139 lowlatency_callback(ACTION_EXIT_MENUITEM
, setting
);
143 MENUITEM_FUNCTION_DYNTEXT(gain_item_0
, MENU_FUNC_USEPARAM
,
144 do_option
, (void*)&gain_0
,
145 gainitem_get_name
, gainitem_speak_item
,
146 &global_settings
.eq_band0_cutoff
, NULL
, Icon_NOICON
);
147 MENUITEM_FUNCTION_DYNTEXT(gain_item_1
, MENU_FUNC_USEPARAM
,
148 do_option
, (void*)&gain_1
,
149 gainitem_get_name
, gainitem_speak_item
,
150 &global_settings
.eq_band1_cutoff
, NULL
, Icon_NOICON
);
151 MENUITEM_FUNCTION_DYNTEXT(gain_item_2
, MENU_FUNC_USEPARAM
,
152 do_option
, (void*)&gain_2
,
153 gainitem_get_name
, gainitem_speak_item
,
154 &global_settings
.eq_band2_cutoff
, NULL
, Icon_NOICON
);
155 MENUITEM_FUNCTION_DYNTEXT(gain_item_3
, MENU_FUNC_USEPARAM
,
156 do_option
, (void*)&gain_3
,
157 gainitem_get_name
, gainitem_speak_item
,
158 &global_settings
.eq_band3_cutoff
, NULL
, Icon_NOICON
);
159 MENUITEM_FUNCTION_DYNTEXT(gain_item_4
, MENU_FUNC_USEPARAM
,
160 do_option
, (void*)&gain_4
,
161 gainitem_get_name
, gainitem_speak_item
,
162 &global_settings
.eq_band4_cutoff
, NULL
, Icon_NOICON
);
164 MAKE_MENU(gain_menu
, ID2P(LANG_EQUALIZER_GAIN
), NULL
, Icon_NOICON
, &gain_item_0
,
165 &gain_item_1
, &gain_item_2
, &gain_item_3
, &gain_item_4
);
167 static const struct menu_item_ex
*band_items
[3][3] = {
168 { &cutoff_1
, &q_1
, &gain_1
},
169 { &cutoff_2
, &q_2
, &gain_2
},
170 { &cutoff_3
, &q_3
, &gain_3
}
173 static char* centerband_get_name(int selected_item
, void * data
, char *buffer
)
176 int band
= (intptr_t)data
;
177 snprintf(buffer
, MAX_PATH
, str(LANG_EQUALIZER_BAND_PEAK
), band
);
181 static int centerband_speak_item(int selected_item
, void * data
)
184 int band
= (intptr_t)data
;
185 talk_id(LANG_EQUALIZER_BAND_PEAK
, false);
186 talk_number(band
, true);
190 static int do_center_band_menu(void* param
)
192 int band
= (intptr_t)param
;
193 struct menu_item_ex menu
;
194 struct menu_callback_with_desc cb_and_desc
;
197 cb_and_desc
.menu_callback
= NULL
;
198 snprintf(desc
, MAX_PATH
, str(LANG_EQUALIZER_BAND_PEAK
), band
);
199 cb_and_desc
.desc
= desc
;
200 cb_and_desc
.icon_id
= Icon_EQ
;
201 menu
.flags
= MT_MENU
|(3<<MENU_COUNT_SHIFT
)|MENU_HAS_DESC
;
202 menu
.submenus
= band_items
[band
-1];
203 menu
.callback_and_desc
= &cb_and_desc
;
204 do_menu(&menu
, NULL
, NULL
, false);
208 MAKE_MENU(band_0_menu
, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF
), NULL
,
209 Icon_EQ
, &cutoff_0
, &q_0
, &gain_0
);
210 MENUITEM_FUNCTION_DYNTEXT(band_1_menu
, MENU_FUNC_USEPARAM
,
211 do_center_band_menu
, (void*)1,
212 centerband_get_name
, centerband_speak_item
,
213 (void*)1, NULL
, Icon_EQ
);
214 MENUITEM_FUNCTION_DYNTEXT(band_2_menu
, MENU_FUNC_USEPARAM
,
215 do_center_band_menu
, (void*)2,
216 centerband_get_name
, centerband_speak_item
,
217 (void*)2, NULL
, Icon_EQ
);
218 MENUITEM_FUNCTION_DYNTEXT(band_3_menu
, MENU_FUNC_USEPARAM
,
219 do_center_band_menu
, (void*)3,
220 centerband_get_name
, centerband_speak_item
,
221 (void*)3, NULL
, Icon_EQ
);
222 MAKE_MENU(band_4_menu
, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF
), NULL
,
223 Icon_EQ
, &cutoff_4
, &q_4
, &gain_4
);
225 MAKE_MENU(advanced_eq_menu_
, ID2P(LANG_EQUALIZER_ADVANCED
), NULL
, Icon_EQ
,
226 &band_0_menu
, &band_1_menu
, &band_2_menu
, &band_3_menu
, &band_4_menu
);
229 enum eq_slider_mode
{
241 /* Draw the UI for a whole EQ band */
242 static int draw_eq_slider(struct screen
* screen
, int x
, int y
,
243 int width
, int cutoff
, int q
, int gain
, bool selected
,
244 enum eq_slider_mode mode
, enum eq_type type
)
247 const char separator
[2] = " ";
248 int steps
, min_item
, max_item
;
249 int abs_gain
= abs(gain
);
250 int current_x
, total_height
, separator_width
, separator_height
;
252 const int slider_height
= 6;
256 steps
= EQ_Q_MAX
- EQ_Q_MIN
;
257 min_item
= q
- EQ_Q_STEP
- EQ_Q_MIN
;
258 max_item
= q
+ EQ_Q_STEP
- EQ_Q_MIN
;
261 steps
= EQ_CUTOFF_MAX
- EQ_CUTOFF_MIN
;
262 min_item
= cutoff
- EQ_CUTOFF_FAST_STEP
* 2;
263 max_item
= cutoff
+ EQ_CUTOFF_FAST_STEP
* 2;
267 steps
= EQ_GAIN_MAX
- EQ_GAIN_MIN
;
268 min_item
= abs(EQ_GAIN_MIN
) + gain
- EQ_GAIN_STEP
* 5;
269 max_item
= abs(EQ_GAIN_MIN
) + gain
+ EQ_GAIN_STEP
* 5;
273 /* Start two pixels in, one for border, one for margin */
276 /* Figure out how large our separator string is */
277 screen
->getstringsize(separator
, &separator_width
, &separator_height
);
279 /* Total height includes margins, text, and line selector */
280 total_height
= separator_height
+ slider_height
+ 2 + 3;
282 /* Print out the band label */
283 if (type
== LOW_SHELF
) {
284 screen
->putsxy(current_x
, y
+ 2, "LS:");
285 screen
->getstringsize("LS:", &w
, &h
);
286 } else if (type
== HIGH_SHELF
) {
287 screen
->putsxy(current_x
, y
+ 2, "HS:");
288 screen
->getstringsize("HS:", &w
, &h
);
290 screen
->putsxy(current_x
, y
+ 2, "PK:");
291 screen
->getstringsize("PK:", &w
, &h
);
295 /* Print separator */
296 screen
->set_drawmode(DRMODE_SOLID
);
297 screen
->putsxy(current_x
, y
+ 2, separator
);
298 current_x
+= separator_width
;
300 if (screen
->screen_type
== SCREEN_REMOTE
) {
302 screen
->putsxy(current_x
, y
+ 2, str(LANG_GAIN
));
303 screen
->getstringsize(str(LANG_GAIN
), &w
, &h
);
304 } else if (mode
== CUTOFF
) {
305 screen
->putsxy(current_x
, y
+ 2, str(LANG_EQUALIZER_BAND_CUTOFF
));
306 screen
->getstringsize(str(LANG_EQUALIZER_BAND_CUTOFF
), &w
, &h
);
308 screen
->putsxy(current_x
, y
+ 2, str(LANG_EQUALIZER_BAND_Q
));
309 screen
->getstringsize(str(LANG_EQUALIZER_BAND_Q
), &w
, &h
);
312 /* Draw horizontal slider. Reuse scrollbar for this */
313 gui_scrollbar_draw(screen
, x
+ 3, y
+ h
+ 3, width
- 6, slider_height
, steps
,
314 min_item
, max_item
, HORIZONTAL
);
316 /* Print out cutoff part */
317 snprintf(buf
, sizeof(buf
), "%sGain %s%2d.%ddB",mode
==GAIN
?" > ":" ", gain
< 0 ? "-" : " ",
318 abs_gain
/ EQ_USER_DIVISOR
, abs_gain
% EQ_USER_DIVISOR
);
319 screen
->getstringsize(buf
, &w
, &h
);
321 screen
->putsxy(0, y
, buf
);
322 /* Print out cutoff part */
323 snprintf(buf
, sizeof(buf
), "%sCutoff %5dHz",mode
==CUTOFF
?" > ":" ", cutoff
);
325 screen
->putsxy(0, y
, buf
);
326 snprintf(buf
, sizeof(buf
), "%sQ setting %d.%d Q",mode
==Q
?" > ":" ", q
/ EQ_USER_DIVISOR
,
327 q
% EQ_USER_DIVISOR
);
329 screen
->putsxy(0, y
, buf
);
334 /* Print out gain part of status line */
335 snprintf(buf
, sizeof(buf
), "%s%2d.%ddB", gain
< 0 ? "-" : " ",
336 abs_gain
/ EQ_USER_DIVISOR
, abs_gain
% EQ_USER_DIVISOR
);
338 if (mode
== GAIN
&& selected
)
339 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
341 screen
->putsxy(current_x
, y
+ 2, buf
);
342 screen
->getstringsize(buf
, &w
, &h
);
345 /* Print separator */
346 screen
->set_drawmode(DRMODE_SOLID
);
347 screen
->putsxy(current_x
, y
+ 2, separator
);
348 current_x
+= separator_width
;
350 /* Print out cutoff part of status line */
351 snprintf(buf
, sizeof(buf
), "%5dHz", cutoff
);
353 if (mode
== CUTOFF
&& selected
)
354 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
356 screen
->putsxy(current_x
, y
+ 2, buf
);
357 screen
->getstringsize(buf
, &w
, &h
);
360 /* Print separator */
361 screen
->set_drawmode(DRMODE_SOLID
);
362 screen
->putsxy(current_x
, y
+ 2, separator
);
363 current_x
+= separator_width
;
365 /* Print out Q part of status line */
366 snprintf(buf
, sizeof(buf
), "%d.%d Q", q
/ EQ_USER_DIVISOR
,
367 q
% EQ_USER_DIVISOR
);
369 if (mode
== Q
&& selected
)
370 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
372 screen
->putsxy(current_x
, y
+ 2, buf
);
373 screen
->getstringsize(buf
, &w
, &h
);
376 screen
->set_drawmode(DRMODE_SOLID
);
378 /* Draw selection box */
380 screen
->drawrect(x
, y
, width
, total_height
);
383 /* Draw horizontal slider. Reuse scrollbar for this */
384 gui_scrollbar_draw(screen
, x
+ 3, y
+ h
+ 3, width
- 6, slider_height
, steps
,
385 min_item
, max_item
, HORIZONTAL
);
390 /* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
391 static int draw_eq_sliders(int current_band
, enum eq_slider_mode mode
)
393 int i
, gain
, q
, cutoff
;
394 int height
= 2; /* Two pixel margin */
395 int slider_width
[NB_SCREENS
];
396 int *setting
= &global_settings
.eq_band0_cutoff
;
400 slider_width
[i
] = screens
[i
].width
- 4; /* two pixel margin on each side */
402 for (i
=0; i
<5; i
++) {
414 height
+= draw_eq_slider(&(screens
[SCREEN_MAIN
]), 2, height
,
415 slider_width
[SCREEN_MAIN
], cutoff
, q
, gain
,
416 i
== current_band
, mode
, type
);
418 if (i
== current_band
)
419 draw_eq_slider(&(screens
[SCREEN_REMOTE
]), 2, 0,
420 slider_width
[SCREEN_REMOTE
], cutoff
, q
, gain
,1, mode
, type
);
429 /* Provides a graphical means of editing the EQ settings */
430 bool eq_menu_graphical(void)
432 bool exit_request
= false;
434 bool has_changed
= false;
437 int current_band
, y
, step
, fast_step
, min
, max
, voice_unit
;
438 enum eq_slider_mode mode
;
439 enum eq_type current_type
;
444 screens
[i
].setfont(FONT_SYSFIXED
);
445 screens
[i
].clear_display();
448 /* Start off editing gain on the first band */
450 current_type
= LOW_SHELF
;
453 while (!exit_request
) {
456 /* Clear the screen. The drawing routines expect this */
457 screens
[i
].clear_display();
458 /* Draw equalizer band details */
459 y
= draw_eq_sliders(current_band
, mode
);
462 /* Set pointer to the band data currently editable */
465 setting
= &global_settings
.eq_band0_gain
;
466 setting
+= current_band
* 3;
469 fast_step
= EQ_GAIN_FAST_STEP
;
472 voice_unit
= UNIT_DB
;
474 snprintf(buf
, sizeof(buf
), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE
),
475 str(LANG_SYSFONT_GAIN
));
477 screens
[SCREEN_MAIN
].putsxy(2, y
, buf
);
478 } else if (mode
== CUTOFF
) {
480 setting
= &global_settings
.eq_band0_cutoff
;
481 setting
+= current_band
* 3;
483 step
= EQ_CUTOFF_STEP
;
484 fast_step
= EQ_CUTOFF_FAST_STEP
;
487 voice_unit
= UNIT_HERTZ
;
489 snprintf(buf
, sizeof(buf
), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE
),
490 str(LANG_SYSFONT_EQUALIZER_BAND_CUTOFF
));
492 screens
[SCREEN_MAIN
].putsxy(2, y
, buf
);
495 setting
= &global_settings
.eq_band0_q
;
496 setting
+= current_band
* 3;
499 fast_step
= EQ_Q_FAST_STEP
;
502 voice_unit
= UNIT_INT
;
504 snprintf(buf
, sizeof(buf
), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE
),
505 str(LANG_EQUALIZER_BAND_Q
));
507 screens
[SCREEN_MAIN
].putsxy(2, y
, buf
);
514 button
= get_action(CONTEXT_SETTINGS_EQ
,TIMEOUT_BLOCK
);
517 case ACTION_SETTINGS_DEC
:
518 case ACTION_SETTINGS_DECREPEAT
:
521 if (*(setting
) < min
)
525 case ACTION_SETTINGS_INC
:
526 case ACTION_SETTINGS_INCREPEAT
:
529 if (*(setting
) > max
)
533 case ACTION_SETTINGS_INCBIGSTEP
:
534 *(setting
) += fast_step
;
536 if (*(setting
) > max
)
540 case ACTION_SETTINGS_DECBIGSTEP
:
541 *(setting
) -= fast_step
;
543 if (*(setting
) < min
)
547 case ACTION_STD_PREV
:
548 case ACTION_STD_PREVREPEAT
:
550 if (current_band
< 0)
551 current_band
= 4; /* wrap around */
554 case ACTION_STD_NEXT
:
555 case ACTION_STD_NEXTREPEAT
:
557 if (current_band
> 4)
558 current_band
= 0; /* wrap around */
564 mode
= GAIN
; /* wrap around */
567 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
);
587 /* Reset screen settings */
589 screens
[i
].setfont(FONT_UI
);
590 screens
[i
].clear_display();
596 static bool eq_save_preset(void)
598 /* make sure that the eq is enabled for setting saving */
599 bool enabled
= global_settings
.eq_enabled
;
600 global_settings
.eq_enabled
= true;
602 bool result
= settings_save_config(SETTINGS_SAVE_EQPRESET
);
604 global_settings
.eq_enabled
= enabled
;
609 /* Allows browsing of preset files */
610 bool eq_browse_presets(void)
612 return rockbox_browse(EQS_DIR
, SHOW_CFG
);
615 MENUITEM_FUNCTION(eq_graphical
, 0, ID2P(LANG_EQUALIZER_GRAPHICAL
),
616 (int(*)(void))eq_menu_graphical
, NULL
, lowlatency_callback
,
618 MENUITEM_FUNCTION(eq_save
, 0, ID2P(LANG_EQUALIZER_SAVE
),
619 (int(*)(void))eq_save_preset
, NULL
, NULL
, Icon_NOICON
);
620 MENUITEM_FUNCTION(eq_browse
, 0, ID2P(LANG_EQUALIZER_BROWSE
),
621 (int(*)(void))eq_browse_presets
, NULL
, lowlatency_callback
,
624 MAKE_MENU(equalizer_menu
, ID2P(LANG_EQUALIZER
), NULL
, Icon_EQ
,
625 &eq_enable
, &eq_graphical
, &eq_precut
, &gain_menu
,
626 &advanced_eq_menu_
, &eq_save
, &eq_browse
);