From 1eb17dc9f4bf280d2e9503f3d0c8b8730146412d Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Tue, 5 Feb 2013 23:20:17 +1100 Subject: EQ settings: Rework the settings to clean up the config file. Instead of 3 cfg lines per eq band there is now a single line for each: : , , In addition, the config value names make a bit more sense. The old settings are still readable but config.cfg and any new settings files will be written with the new config values. (The old settings will be removed completly sometime after the next stable release). Also a slight rework of the advanced EQ menu UI Change-Id: I9008658d36ded442a5f2f825916df42a3934cbef Reviewed-on: http://gerrit.rockbox.org/394 Reviewed-by: Jonathan Gordon --- apps/menus/eq_menu.c | 552 +++++++++++++++++++++++++++++---------------------- 1 file changed, 314 insertions(+), 238 deletions(-) (limited to 'apps/menus') diff --git a/apps/menus/eq_menu.c b/apps/menus/eq_menu.c index 2f3d6b62c7..8285850155 100644 --- a/apps/menus/eq_menu.c +++ b/apps/menus/eq_menu.c @@ -27,6 +27,7 @@ #include "system.h" #include "kernel.h" #include "lcd.h" +#include "list.h" #include "menu.h" #include "action.h" #include "mp3_playback.h" @@ -46,6 +47,8 @@ #include "menu_common.h" #include "viewport.h" #include "exported_menus.h" +#include "pcmbuf.h" +#include "option_select.h" /* * Utility functions @@ -70,8 +73,8 @@ const char* eq_precut_format(char* buffer, size_t buffer_size, int value, const */ static void eq_apply(void) { - dsp_eq_enable(global_settings.eq_enabled); - dsp_set_eq_precut(global_settings.eq_precut); + dsp_eq_enable(global_settings.eq_enabled); + dsp_set_eq_precut(global_settings.eq_precut); /* Update all bands */ for(int i = 0; i < EQ_NUM_BANDS; i++) { dsp_set_eq_coefs(i, &global_settings.eq_band_settings[i]); @@ -96,239 +99,315 @@ static int eq_setting_callback(int action, const struct menu_item_ex *this_item) MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, eq_setting_callback); MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, eq_setting_callback); -MENUITEM_SETTING(cutoff_0, &global_settings.eq_band_settings[0].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_1, &global_settings.eq_band_settings[1].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_2, &global_settings.eq_band_settings[2].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_3, &global_settings.eq_band_settings[3].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_4, &global_settings.eq_band_settings[4].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_5, &global_settings.eq_band_settings[5].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_6, &global_settings.eq_band_settings[6].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_7, &global_settings.eq_band_settings[7].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_8, &global_settings.eq_band_settings[8].cutoff, - eq_setting_callback); -MENUITEM_SETTING(cutoff_9, &global_settings.eq_band_settings[9].cutoff, - eq_setting_callback); - -MENUITEM_SETTING(q_0, &global_settings.eq_band_settings[0].q, - eq_setting_callback); -MENUITEM_SETTING(q_1, &global_settings.eq_band_settings[1].q, - eq_setting_callback); -MENUITEM_SETTING(q_2, &global_settings.eq_band_settings[2].q, - eq_setting_callback); -MENUITEM_SETTING(q_3, &global_settings.eq_band_settings[3].q, - eq_setting_callback); -MENUITEM_SETTING(q_4, &global_settings.eq_band_settings[4].q, - eq_setting_callback); -MENUITEM_SETTING(q_5, &global_settings.eq_band_settings[5].q, - eq_setting_callback); -MENUITEM_SETTING(q_6, &global_settings.eq_band_settings[6].q, - eq_setting_callback); -MENUITEM_SETTING(q_7, &global_settings.eq_band_settings[7].q, - eq_setting_callback); -MENUITEM_SETTING(q_8, &global_settings.eq_band_settings[8].q, - eq_setting_callback); -MENUITEM_SETTING(q_9, &global_settings.eq_band_settings[9].q, - eq_setting_callback); - -MENUITEM_SETTING(gain_0, &global_settings.eq_band_settings[0].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_1, &global_settings.eq_band_settings[1].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_2, &global_settings.eq_band_settings[2].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_3, &global_settings.eq_band_settings[3].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_4, &global_settings.eq_band_settings[4].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_5, &global_settings.eq_band_settings[5].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_6, &global_settings.eq_band_settings[6].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_7, &global_settings.eq_band_settings[7].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_8, &global_settings.eq_band_settings[8].gain, - eq_setting_callback); -MENUITEM_SETTING(gain_9, &global_settings.eq_band_settings[9].gain, - eq_setting_callback); - -static char* gainitem_get_name(int selected_item, void * data, char *buffer) +static char* gainitem_get_name(int selected_item, void *data, char *buffer, size_t len) { - (void)selected_item; - int *setting = (int*)data; - snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_GAIN_ITEM), *setting); + (void)data; + snprintf(buffer, len, str(LANG_EQUALIZER_GAIN_ITEM), + global_settings.eq_band_settings[selected_item].cutoff); + return buffer; } -static int gainitem_speak_item(int selected_item, void * data) +static int gainitem_speak_item(int selected_item, void *data) { - (void)selected_item; - int *setting = (int*)data; - talk_number(*setting, false); + (void)data; + talk_number(global_settings.eq_band_settings[selected_item].cutoff, false); talk_id(LANG_EQUALIZER_GAIN_ITEM, true); return 0; } -static int do_option(void * param) +static enum themable_icons gainitem_get_icon(int selected_item, void * data) { - const struct menu_item_ex *setting = (const struct menu_item_ex*)param; - lowlatency_callback(ACTION_ENTER_MENUITEM, setting); - do_setting_from_menu(setting, NULL); - eq_apply(); - lowlatency_callback(ACTION_EXIT_MENUITEM, setting); - return 0; + (void)selected_item; + (void)data; + + return Icon_Menu_functioncall; } -MENUITEM_FUNCTION_DYNTEXT(gain_item_0, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_0, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[0].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_1, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_1, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[1].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_2, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_2, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[2].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_3, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_3, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[3].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_4, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_4, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[4].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_5, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_5, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[5].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_6, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_6, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[6].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_7, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_7, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[7].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_8, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_8, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[8].cutoff, - NULL, Icon_NOICON); -MENUITEM_FUNCTION_DYNTEXT(gain_item_9, MENU_FUNC_USEPARAM, - do_option, (void*)&gain_9, - gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band_settings[9].cutoff, - NULL, Icon_NOICON); - -MAKE_MENU(gain_menu, ID2P(LANG_EQUALIZER_GAIN), NULL, Icon_NOICON, &gain_item_0, - &gain_item_1, &gain_item_2, &gain_item_3, &gain_item_4, - &gain_item_5, &gain_item_6, &gain_item_7, &gain_item_8, - &gain_item_9); - -static const struct menu_item_ex *band_items[8][3] = { - { &cutoff_1, &q_1, &gain_1 }, - { &cutoff_2, &q_2, &gain_2 }, - { &cutoff_3, &q_3, &gain_3 }, - { &cutoff_4, &q_4, &gain_4 }, - { &cutoff_5, &q_5, &gain_5 }, - { &cutoff_6, &q_6, &gain_6 }, - { &cutoff_7, &q_7, &gain_7 }, - { &cutoff_8, &q_8, &gain_8 } +static const char* db_format(char* buffer, size_t buffer_size, int value, + const char* unit) +{ + int v = abs(value); + + snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "", + v / 10, v % 10, unit); + return buffer; +} + +static int32_t get_dec_talkid(int value, int unit) +{ + return TALK_ID_DECIMAL(value, 1, unit); +} + +static const struct int_setting gain_int_setting = { + .option_callback = NULL, + .unit = UNIT_DB, + .min = EQ_GAIN_MIN, + .max = EQ_GAIN_MAX, + .step = EQ_GAIN_STEP, + .formatter = db_format, + .get_talk_id = get_dec_talkid, +}; + +static const struct int_setting q_int_setting = { + .option_callback = NULL, + .unit = UNIT_INT, + .min = EQ_Q_MIN, + .max = EQ_Q_MAX, + .step = EQ_Q_STEP, + .formatter = eq_q_format, + .get_talk_id = get_dec_talkid, +}; + +static const struct int_setting cutoff_int_setting = { + .option_callback = NULL, + .unit = UNIT_HERTZ, + .min = EQ_CUTOFF_MIN, + .max = EQ_CUTOFF_MAX, + .step = EQ_CUTOFF_STEP, + .formatter = NULL, + .get_talk_id = NULL, }; -static char* centerband_get_name(int selected_item, void * data, char *buffer) +static int simplelist_action_callback(int action, struct gui_synclist *lists) { - (void)selected_item; - int band = (intptr_t)data; - snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band); - return buffer; + (void)lists; + if (action == ACTION_STD_OK) + return ACTION_STD_CANCEL; + return action; } -static int centerband_speak_item(int selected_item, void * data) +static int eq_do_simple_menu(void * param) { - (void)selected_item; - int band = (intptr_t)data; - talk_id(LANG_EQUALIZER_BAND_PEAK, false); - talk_number(band, true); + (void)param; + struct simplelist_info info; + struct settings_list setting; + char title[MAX_PATH]; + + simplelist_info_init(&info, str(LANG_EQUALIZER_GAIN), EQ_NUM_BANDS, NULL); + info.get_name = (list_get_name*)gainitem_get_name; + info.get_talk = gainitem_speak_item; + info.get_icon = gainitem_get_icon; + info.action_callback = simplelist_action_callback; + info.selection = -1; + info.title_icon = Icon_Submenu; + setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP; + setting.lang_id = LANG_GAIN; + setting.default_val.int_ = 0; + setting.int_setting = &gain_int_setting; + + while (true) + { + simplelist_show_list(&info); + if (info.selection < 0) + break; + pcmbuf_set_low_latency(true); + setting.setting = &global_settings.eq_band_settings[info.selection].gain; + option_screen(&setting, NULL, false, + gainitem_get_name(info.selection, NULL, title, MAX_PATH)); + eq_apply(); + pcmbuf_set_low_latency(false); + } return 0; } +MENUITEM_FUNCTION(gain_menu, 0, ID2P(LANG_EQUALIZER_GAIN), eq_do_simple_menu, + NULL, NULL, Icon_Submenu); -static int do_center_band_menu(void* param) +static void selection_to_banditem(int selection, int expanded_band, int *band, int *item) { - int band = (intptr_t)param; - struct menu_item_ex menu; - struct menu_callback_with_desc cb_and_desc; - char desc[MAX_PATH]; - - cb_and_desc.menu_callback = NULL; - snprintf(desc, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band); - cb_and_desc.desc = desc; - cb_and_desc.icon_id = Icon_EQ; - menu.flags = MT_MENU|(3<putsxy(x1, y1, "LS: "); screen->getstringsize("LS:", &w, &h); - } else if (band == 9) { + } else if (band == EQ_NUM_BANDS - 1) { screen->putsxy(x1, y1, "HS: "); screen->getstringsize("HS:", &w, &h); } else { @@ -425,7 +504,7 @@ static int draw_eq_slider(struct screen * screen, int x, int y, screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID); else screen->set_drawmode(DRMODE_SOLID); - + snprintf(buf, sizeof(buf), "%5d%s", cutoff, screen->lcdwidth >= 160 ? "Hz" : ""); screen->getstringsize(buf, &w, &h); @@ -453,9 +532,9 @@ static void draw_eq_sliders(struct screen * screen, int x, int y, { int height = y; - start_item = MIN(start_item, 10 - nb_eq_sliders); + start_item = MIN(start_item, EQ_NUM_BANDS - nb_eq_sliders); - for (int i = 0; i < 10; i++) { + for (int i = 0; i < EQ_NUM_BANDS; i++) { struct eq_band_setting *setting = &global_settings.eq_band_settings[i]; int cutoff = setting->cutoff; int q = setting->q; @@ -473,9 +552,9 @@ static void draw_eq_sliders(struct screen * screen, int x, int y, } } - if (nb_eq_sliders != 10) + if (nb_eq_sliders != EQ_NUM_BANDS) gui_scrollbar_draw(screen, 0, y, SCROLLBAR_SIZE - 1, - screen->lcdheight - y, 10, + screen->lcdheight - y, EQ_NUM_BANDS, start_item, start_item + nb_eq_sliders, VERTICAL); return; @@ -514,16 +593,16 @@ bool eq_menu_graphical(void) if (height > screens[i].lcdheight) nb_eq_sliders[i]--; - if (nb_eq_sliders[i] > 10) - nb_eq_sliders[i] = 10; + if (nb_eq_sliders[i] > EQ_NUM_BANDS) + nb_eq_sliders[i] = EQ_NUM_BANDS; } y = h + 1; - + /* Start off editing gain on the first band */ mode = GAIN; current_band = 0; - + while (!exit_request) { FOR_NB_SCREENS(i) { @@ -538,7 +617,7 @@ bool eq_menu_graphical(void) fast_step = EQ_GAIN_FAST_STEP; min = EQ_GAIN_MIN; max = EQ_GAIN_MAX; - + snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE), str(LANG_SYSFONT_GAIN), "(dB)"); @@ -572,12 +651,12 @@ bool eq_menu_graphical(void) } /* Draw scrollbar if needed */ - if (nb_eq_sliders[i] != 10) + if (nb_eq_sliders[i] != EQ_NUM_BANDS) { if (current_band == 0) { start_item = 0; } else if (current_band == 9) { - start_item = 10 - nb_eq_sliders[i]; + start_item = EQ_NUM_BANDS - nb_eq_sliders[i]; } else { start_item = current_band - 1; } @@ -592,7 +671,7 @@ bool eq_menu_graphical(void) screens[i].update(); } - + button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK); switch (button) { @@ -630,14 +709,12 @@ bool eq_menu_graphical(void) case ACTION_STD_PREVREPEAT: current_band--; if (current_band < 0) - current_band = 9; /* wrap around */ + current_band = EQ_NUM_BANDS - 1; /* wrap around */ break; case ACTION_STD_NEXT: case ACTION_STD_NEXTREPEAT: - current_band++; - if (current_band > 9) - current_band = 0; /* wrap around */ + current_band = (current_band + 1) % EQ_NUM_BANDS; break; case ACTION_STD_OK: @@ -657,7 +734,7 @@ bool eq_menu_graphical(void) } break; } - + /* Update the filter if the user changed something */ if (has_changed) { dsp_set_eq_coefs(current_band, @@ -667,7 +744,7 @@ bool eq_menu_graphical(void) } /* Reset screen settings */ - FOR_NB_SCREENS(i) + FOR_NB_SCREENS(i) { screens[i].setfont(FONT_UI); screens[i].clear_display(); @@ -682,19 +759,18 @@ static bool eq_save_preset(void) /* make sure that the eq is enabled for setting saving */ bool enabled = global_settings.eq_enabled; global_settings.eq_enabled = true; - + bool result = settings_save_config(SETTINGS_SAVE_EQPRESET); - + global_settings.eq_enabled = enabled; return result; } - /* Allows browsing of preset files */ static struct browse_folder_info eqs = { EQS_DIR, SHOW_CFG }; MENUITEM_FUNCTION(eq_graphical, 0, ID2P(LANG_EQUALIZER_GRAPHICAL), - (int(*)(void))eq_menu_graphical, NULL, lowlatency_callback, + (int(*)(void))eq_menu_graphical, NULL, lowlatency_callback, Icon_EQ); MENUITEM_FUNCTION(eq_save, 0, ID2P(LANG_EQUALIZER_SAVE), (int(*)(void))eq_save_preset, NULL, NULL, Icon_NOICON); @@ -703,6 +779,6 @@ MENUITEM_FUNCTION(eq_browse, MENU_FUNC_USEPARAM, ID2P(LANG_EQUALIZER_BROWSE), Icon_NOICON); MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), NULL, Icon_EQ, - &eq_enable, &eq_graphical, &eq_precut, &gain_menu, - &advanced_eq_menu_, &eq_save, &eq_browse); + &eq_enable, &eq_graphical, &eq_precut, &gain_menu, + &advanced_menu, &eq_save, &eq_browse); -- cgit v1.2.3