2007-02-19 02:14:51 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-01-03 14:28:09 +00:00
|
|
|
* $Id$
|
2007-02-19 02:14:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Dan Everton
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-02-19 02:14:51 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "eq_menu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "lcd.h"
|
2013-02-05 12:20:17 +00:00
|
|
|
#include "list.h"
|
2007-02-19 02:14:51 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "action.h"
|
|
|
|
#include "mp3_playback.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "talk.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "sound.h"
|
2012-04-29 21:31:30 +00:00
|
|
|
#include "dsp_proc_settings.h"
|
2007-02-19 02:14:51 +00:00
|
|
|
#include "tree.h"
|
|
|
|
#include "screen_access.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "gui/scrollbar.h"
|
2008-03-03 11:06:04 +00:00
|
|
|
#include "menu_common.h"
|
2009-01-05 09:59:11 +00:00
|
|
|
#include "viewport.h"
|
2010-07-25 18:28:42 +00:00
|
|
|
#include "exported_menus.h"
|
2013-02-05 12:20:17 +00:00
|
|
|
#include "pcmbuf.h"
|
|
|
|
#include "option_select.h"
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility functions
|
|
|
|
*/
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
const char* eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2009-08-20 16:47:44 +00:00
|
|
|
snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR,
|
|
|
|
value % EQ_USER_DIVISOR, unit);
|
|
|
|
return buffer;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
const char* eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
|
|
|
snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
|
|
|
|
value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
|
2009-08-20 16:47:44 +00:00
|
|
|
return buffer;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Settings functions
|
|
|
|
*/
|
2008-03-30 09:31:09 +00:00
|
|
|
static void eq_apply(void)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
dsp_eq_enable(global_settings.eq_enabled);
|
|
|
|
dsp_set_eq_precut(global_settings.eq_precut);
|
2007-09-25 02:44:50 +00:00
|
|
|
/* Update all bands */
|
2012-03-27 23:52:15 +00:00
|
|
|
for(int i = 0; i < EQ_NUM_BANDS; i++) {
|
|
|
|
dsp_set_eq_coefs(i, &global_settings.eq_band_settings[i]);
|
2007-09-25 02:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-03-30 09:31:09 +00:00
|
|
|
static int eq_setting_callback(int action, const struct menu_item_ex *this_item)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2008-03-30 09:31:09 +00:00
|
|
|
switch (action)
|
2007-02-19 04:28:56 +00:00
|
|
|
{
|
2008-03-30 09:31:09 +00:00
|
|
|
case ACTION_ENTER_MENUITEM:
|
|
|
|
action = lowlatency_callback(action, this_item);
|
|
|
|
break;
|
|
|
|
case ACTION_EXIT_MENUITEM:
|
|
|
|
eq_apply();
|
|
|
|
action = lowlatency_callback(action, this_item);
|
|
|
|
break;
|
2007-02-19 04:28:56 +00:00
|
|
|
}
|
2008-03-30 09:31:09 +00:00
|
|
|
|
2007-02-19 04:28:56 +00:00
|
|
|
return action;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
2008-03-30 09:31:09 +00:00
|
|
|
MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, eq_setting_callback);
|
|
|
|
MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, eq_setting_callback);
|
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static char* gainitem_get_name(int selected_item, void *data, char *buffer, size_t len)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
(void)data;
|
|
|
|
snprintf(buffer, len, str(LANG_EQUALIZER_GAIN_ITEM),
|
|
|
|
global_settings.eq_band_settings[selected_item].cutoff);
|
|
|
|
|
2007-02-19 04:28:56 +00:00
|
|
|
return buffer;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
2008-03-30 09:31:09 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static int gainitem_speak_item(int selected_item, void *data)
|
2007-10-09 03:53:46 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
(void)data;
|
|
|
|
talk_number(global_settings.eq_band_settings[selected_item].cutoff, false);
|
2007-10-09 03:53:46 +00:00
|
|
|
talk_id(LANG_EQUALIZER_GAIN_ITEM, true);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static enum themable_icons gainitem_get_icon(int selected_item, void * data)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
(void)selected_item;
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
return Icon_Menu_functioncall;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
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,
|
2007-02-19 02:14:51 +00:00
|
|
|
};
|
2008-03-30 09:31:09 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static int simplelist_action_callback(int action, struct gui_synclist *lists)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
(void)lists;
|
|
|
|
if (action == ACTION_STD_OK)
|
|
|
|
return ACTION_STD_CANCEL;
|
|
|
|
return action;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
2008-03-30 09:31:09 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static int eq_do_simple_menu(void * param)
|
2007-10-09 03:53:46 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
(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);
|
|
|
|
}
|
2007-10-09 03:53:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-02-05 12:20:17 +00:00
|
|
|
MENUITEM_FUNCTION(gain_menu, 0, ID2P(LANG_EQUALIZER_GAIN), eq_do_simple_menu,
|
|
|
|
NULL, NULL, Icon_Submenu);
|
2008-03-30 09:31:09 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static void selection_to_banditem(int selection, int expanded_band, int *band, int *item)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2013-02-05 12:20:17 +00:00
|
|
|
int diff = selection - expanded_band;
|
|
|
|
|
|
|
|
if (expanded_band < 0 || diff < 0)
|
|
|
|
{
|
|
|
|
*item = 0;
|
|
|
|
*band = selection;
|
|
|
|
}
|
|
|
|
else if (diff < 4)
|
|
|
|
{
|
|
|
|
*item = selection - expanded_band;
|
|
|
|
*band = expanded_band;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*item = 0;
|
|
|
|
*band = expanded_band + diff - 3;
|
|
|
|
}
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
2008-03-30 09:31:09 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
static char *advancedmenu_item_get_name(int selected_item, void *data, char *buffer, size_t len)
|
|
|
|
{
|
|
|
|
(void)len;
|
|
|
|
int band;
|
|
|
|
int item;
|
|
|
|
char *lang = NULL;
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
selection_to_banditem(selected_item, *(intptr_t*)data, &band, &item);
|
|
|
|
|
|
|
|
strcpy(buffer, "\t");
|
|
|
|
switch (item)
|
|
|
|
{
|
|
|
|
case 0: /* Band title */
|
|
|
|
if (band == 0)
|
|
|
|
return str(LANG_EQUALIZER_BAND_LOW_SHELF);
|
|
|
|
else if (band == EQ_NUM_BANDS - 1)
|
|
|
|
return str(LANG_EQUALIZER_BAND_HIGH_SHELF);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: /* cutoff */
|
|
|
|
if (band == 0)
|
|
|
|
lang = str(LANG_EQUALIZER_BAND_CUTOFF);
|
|
|
|
else if (band == EQ_NUM_BANDS - 1)
|
|
|
|
lang = str(LANG_EQUALIZER_BAND_CUTOFF);
|
|
|
|
else
|
|
|
|
lang = str(LANG_EQUALIZER_BAND_CENTER);
|
|
|
|
break;
|
|
|
|
case 2: /* Q */
|
|
|
|
lang = str(LANG_EQUALIZER_BAND_Q);
|
|
|
|
break;
|
|
|
|
case 3: /* Gain */
|
|
|
|
lang = str(LANG_GAIN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strcat(buffer, lang);;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int advancedmenu_speak_item(int selected_item, void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
int band;
|
|
|
|
int item;
|
|
|
|
int lang = -1;
|
|
|
|
|
|
|
|
selection_to_banditem(selected_item, *(intptr_t*)data, &band, &item);
|
|
|
|
|
|
|
|
switch (item)
|
|
|
|
{
|
|
|
|
case 0: /* Band title */
|
|
|
|
if (band == 0)
|
|
|
|
lang = LANG_EQUALIZER_BAND_LOW_SHELF;
|
|
|
|
else if (band == EQ_NUM_BANDS - 1)
|
|
|
|
lang = LANG_EQUALIZER_BAND_HIGH_SHELF;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
talk_id(LANG_EQUALIZER_BAND_PEAK, false);
|
|
|
|
talk_number(band, true);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: /* cutoff */
|
|
|
|
if (band == 0)
|
|
|
|
lang = LANG_EQUALIZER_BAND_CUTOFF;
|
|
|
|
else if (band == EQ_NUM_BANDS - 1)
|
|
|
|
lang = LANG_EQUALIZER_BAND_CUTOFF;
|
|
|
|
else
|
|
|
|
lang = LANG_EQUALIZER_BAND_CENTER;
|
|
|
|
break;
|
|
|
|
case 2: /* Q */
|
|
|
|
lang = LANG_EQUALIZER_BAND_Q;
|
|
|
|
break;
|
|
|
|
case 3: /* Gain */
|
|
|
|
lang = LANG_GAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
talk_id(lang, true);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum themable_icons advancedmenu_get_icon(int selected_item, void * data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
int band;
|
|
|
|
int item;
|
|
|
|
|
|
|
|
selection_to_banditem(selected_item, *(intptr_t*)data, &band, &item);
|
|
|
|
|
|
|
|
if (item == 0)
|
|
|
|
return Icon_Submenu;
|
|
|
|
else
|
|
|
|
return Icon_Menu_setting;
|
|
|
|
}
|
|
|
|
extern struct eq_band_setting eq_defaults[EQ_NUM_BANDS];
|
|
|
|
|
|
|
|
static int eq_do_advanced_menu(void * param)
|
|
|
|
{
|
|
|
|
(void)param;
|
|
|
|
struct simplelist_info info;
|
|
|
|
struct settings_list setting;
|
|
|
|
char title[MAX_PATH];
|
|
|
|
int band, item;
|
|
|
|
intptr_t selected_band = -1;
|
|
|
|
|
|
|
|
simplelist_info_init(&info, str(LANG_EQUALIZER_ADVANCED),
|
|
|
|
EQ_NUM_BANDS, &selected_band);
|
|
|
|
info.get_name = (list_get_name*)advancedmenu_item_get_name;
|
|
|
|
info.get_talk = advancedmenu_speak_item;
|
|
|
|
info.get_icon = advancedmenu_get_icon;
|
|
|
|
info.action_callback = simplelist_action_callback;
|
|
|
|
info.selection = -1;
|
|
|
|
info.title_icon = Icon_EQ;
|
|
|
|
setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
simplelist_show_list(&info);
|
|
|
|
if (info.selection < 0)
|
|
|
|
break;
|
|
|
|
selection_to_banditem(info.selection, selected_band, &band, &item);
|
|
|
|
switch (item)
|
|
|
|
{
|
|
|
|
case 0: /* title, do nothing */
|
|
|
|
{
|
|
|
|
int extra;
|
|
|
|
if (selected_band == band)
|
|
|
|
{
|
|
|
|
extra = 0;
|
|
|
|
selected_band = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
extra = 3;
|
|
|
|
selected_band = band;
|
|
|
|
}
|
|
|
|
info.selection = band;
|
|
|
|
info.count = EQ_NUM_BANDS + extra;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case 1: /* cutoff */
|
|
|
|
if (band == 0 || band == EQ_NUM_BANDS - 1)
|
|
|
|
setting.lang_id = LANG_EQUALIZER_BAND_CUTOFF;
|
|
|
|
else
|
|
|
|
setting.lang_id = LANG_EQUALIZER_BAND_CENTER;
|
|
|
|
setting.default_val.int_ = eq_defaults[band].cutoff;
|
|
|
|
setting.int_setting = &cutoff_int_setting;
|
2013-02-18 07:46:24 +00:00
|
|
|
setting.setting = &global_settings.eq_band_settings[band].cutoff;
|
2013-02-05 12:20:17 +00:00
|
|
|
break;
|
|
|
|
case 2: /* Q */
|
|
|
|
setting.lang_id = LANG_EQUALIZER_BAND_Q;
|
|
|
|
setting.default_val.int_ = eq_defaults[band].q;
|
|
|
|
setting.int_setting = &q_int_setting;
|
2013-02-18 07:46:24 +00:00
|
|
|
setting.setting = &global_settings.eq_band_settings[band].q;
|
2013-02-05 12:20:17 +00:00
|
|
|
break;
|
|
|
|
case 3: /* Gain */
|
|
|
|
setting.lang_id = LANG_GAIN;
|
|
|
|
setting.default_val.int_ = eq_defaults[band].gain;
|
|
|
|
setting.int_setting = &gain_int_setting;
|
2013-02-18 07:46:24 +00:00
|
|
|
setting.setting = &global_settings.eq_band_settings[band].gain;
|
2013-02-05 12:20:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pcmbuf_set_low_latency(true);
|
|
|
|
advancedmenu_item_get_name(info.selection, &selected_band, title, MAX_PATH);
|
|
|
|
|
|
|
|
option_screen(&setting, NULL, false, title[0] == '\t' ? &title[1] : title);
|
|
|
|
eq_apply();
|
|
|
|
pcmbuf_set_low_latency(false);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MENUITEM_FUNCTION(advanced_menu, 0, ID2P(LANG_EQUALIZER_ADVANCED),
|
|
|
|
eq_do_advanced_menu, NULL, NULL, Icon_EQ);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
enum eq_slider_mode {
|
|
|
|
GAIN,
|
|
|
|
CUTOFF,
|
|
|
|
Q,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum eq_type {
|
|
|
|
LOW_SHELF,
|
|
|
|
PEAK,
|
|
|
|
HIGH_SHELF
|
|
|
|
};
|
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
/* Size of just the slider/srollbar */
|
|
|
|
#define SCROLLBAR_SIZE 6
|
|
|
|
|
2007-02-19 02:14:51 +00:00
|
|
|
/* Draw the UI for a whole EQ band */
|
|
|
|
static int draw_eq_slider(struct screen * screen, int x, int y,
|
|
|
|
int width, int cutoff, int q, int gain, bool selected,
|
2008-11-09 10:28:04 +00:00
|
|
|
enum eq_slider_mode mode, int band)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
|
|
|
char buf[26];
|
|
|
|
int steps, min_item, max_item;
|
|
|
|
int abs_gain = abs(gain);
|
2008-11-09 10:28:04 +00:00
|
|
|
int x1, x2, y1, total_height;
|
2007-02-19 02:14:51 +00:00
|
|
|
int w, h;
|
|
|
|
|
|
|
|
switch(mode) {
|
|
|
|
case Q:
|
|
|
|
steps = EQ_Q_MAX - EQ_Q_MIN;
|
|
|
|
min_item = q - EQ_Q_STEP - EQ_Q_MIN;
|
|
|
|
max_item = q + EQ_Q_STEP - EQ_Q_MIN;
|
2013-02-05 12:20:17 +00:00
|
|
|
break;
|
2007-02-19 02:14:51 +00:00
|
|
|
case CUTOFF:
|
|
|
|
steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN;
|
|
|
|
min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2;
|
|
|
|
max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2;
|
2013-02-05 12:20:17 +00:00
|
|
|
break;
|
2007-02-19 02:14:51 +00:00
|
|
|
case GAIN:
|
|
|
|
default:
|
|
|
|
steps = EQ_GAIN_MAX - EQ_GAIN_MIN;
|
|
|
|
min_item = abs(EQ_GAIN_MIN) + gain - EQ_GAIN_STEP * 5;
|
|
|
|
max_item = abs(EQ_GAIN_MIN) + gain + EQ_GAIN_STEP * 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start two pixels in, one for border, one for margin */
|
2008-11-09 10:28:04 +00:00
|
|
|
x1 = x + 2;
|
|
|
|
y1 = y + 2;
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
/* Print out the band label */
|
2008-11-09 10:28:04 +00:00
|
|
|
if (band == 0) {
|
|
|
|
screen->putsxy(x1, y1, "LS: ");
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->getstringsize("LS:", &w, &h);
|
2013-02-05 12:20:17 +00:00
|
|
|
} else if (band == EQ_NUM_BANDS - 1) {
|
2008-11-09 10:28:04 +00:00
|
|
|
screen->putsxy(x1, y1, "HS: ");
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->getstringsize("HS:", &w, &h);
|
|
|
|
} else {
|
2008-11-09 10:28:04 +00:00
|
|
|
snprintf(buf, sizeof(buf), "PK%d:", band);
|
|
|
|
screen->putsxy(x1, y1, buf);
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->getstringsize(buf, &w, &h);
|
|
|
|
}
|
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
screen->getstringsize("A", &w, &h);
|
|
|
|
x1 += 5*w; /* 4 chars for label + 1 space = 5 */
|
|
|
|
|
|
|
|
/* Print out gain part of status line (left justify after label) */
|
2007-02-19 02:14:51 +00:00
|
|
|
if (mode == GAIN && selected)
|
|
|
|
screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
|
2008-11-09 10:28:04 +00:00
|
|
|
else
|
|
|
|
screen->set_drawmode(DRMODE_SOLID);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s%2d.%d%s", gain < 0 ? "-" : " ",
|
|
|
|
abs_gain / EQ_USER_DIVISOR, abs_gain % EQ_USER_DIVISOR,
|
|
|
|
screen->lcdwidth >= 160 ? "dB" : "");
|
|
|
|
screen->putsxy(x1, y1, buf);
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->getstringsize(buf, &w, &h);
|
2008-11-09 10:28:04 +00:00
|
|
|
x1 += w;
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
/* Print out Q part of status line (right justify) */
|
|
|
|
if (mode == Q && selected)
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
|
2008-11-09 10:28:04 +00:00
|
|
|
else
|
|
|
|
screen->set_drawmode(DRMODE_SOLID);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%d.%d%s", q / EQ_USER_DIVISOR,
|
|
|
|
q % EQ_USER_DIVISOR, screen->lcdwidth >= 160 ? " Q" : "");
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->getstringsize(buf, &w, &h);
|
2008-11-09 10:28:04 +00:00
|
|
|
x2 = x + width - w - 2;
|
|
|
|
screen->putsxy(x2, y1, buf);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
/* Print out cutoff part of status line (center between gain & Q) */
|
|
|
|
if (mode == CUTOFF && selected)
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
|
2008-11-09 10:28:04 +00:00
|
|
|
else
|
|
|
|
screen->set_drawmode(DRMODE_SOLID);
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%5d%s", cutoff,
|
|
|
|
screen->lcdwidth >= 160 ? "Hz" : "");
|
2007-02-19 02:14:51 +00:00
|
|
|
screen->getstringsize(buf, &w, &h);
|
2008-11-09 10:28:04 +00:00
|
|
|
x1 = x1 + (x2 - x1 - w)/2;
|
|
|
|
screen->putsxy(x1, y1, buf);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
/* Draw selection box */
|
2008-11-09 10:28:04 +00:00
|
|
|
total_height = 3 + h + 1 + SCROLLBAR_SIZE + 3;
|
|
|
|
screen->set_drawmode(DRMODE_SOLID);
|
2007-02-19 02:14:51 +00:00
|
|
|
if (selected) {
|
|
|
|
screen->drawrect(x, y, width, total_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw horizontal slider. Reuse scrollbar for this */
|
2008-11-09 10:28:04 +00:00
|
|
|
gui_scrollbar_draw(screen, x + 3, y1 + h + 1, width - 6, SCROLLBAR_SIZE,
|
|
|
|
steps, min_item, max_item, HORIZONTAL);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
return total_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw's all the EQ sliders. Returns the total height of the sliders drawn */
|
2008-11-09 10:28:04 +00:00
|
|
|
static void draw_eq_sliders(struct screen * screen, int x, int y,
|
|
|
|
int nb_eq_sliders, int start_item,
|
|
|
|
int current_band, enum eq_slider_mode mode)
|
2007-02-19 02:14:51 +00:00
|
|
|
{
|
2008-11-09 10:28:04 +00:00
|
|
|
int height = y;
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
start_item = MIN(start_item, EQ_NUM_BANDS - nb_eq_sliders);
|
2012-03-09 21:38:33 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
for (int i = 0; i < EQ_NUM_BANDS; i++) {
|
2012-03-09 21:38:33 +00:00
|
|
|
struct eq_band_setting *setting = &global_settings.eq_band_settings[i];
|
|
|
|
int cutoff = setting->cutoff;
|
|
|
|
int q = setting->q;
|
|
|
|
int gain = setting->gain;
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
if (i == start_item + nb_eq_sliders)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i >= start_item) {
|
|
|
|
height += draw_eq_slider(screen, x, height, screen->lcdwidth - x - 1,
|
|
|
|
cutoff, q, gain, i == current_band, mode,
|
|
|
|
i);
|
|
|
|
/* add a margin */
|
|
|
|
height++;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 21:38:33 +00:00
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
if (nb_eq_sliders != EQ_NUM_BANDS)
|
2008-11-09 10:28:04 +00:00
|
|
|
gui_scrollbar_draw(screen, 0, y, SCROLLBAR_SIZE - 1,
|
2013-02-05 12:20:17 +00:00
|
|
|
screen->lcdheight - y, EQ_NUM_BANDS,
|
2008-11-09 10:28:04 +00:00
|
|
|
start_item, start_item + nb_eq_sliders,
|
|
|
|
VERTICAL);
|
|
|
|
return;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Provides a graphical means of editing the EQ settings */
|
|
|
|
bool eq_menu_graphical(void)
|
|
|
|
{
|
|
|
|
bool exit_request = false;
|
|
|
|
bool result = true;
|
|
|
|
bool has_changed = false;
|
|
|
|
int button;
|
|
|
|
int *setting;
|
2010-09-21 09:10:01 +00:00
|
|
|
int current_band, x, y, step, fast_step, min, max;
|
2007-02-19 02:14:51 +00:00
|
|
|
enum eq_slider_mode mode;
|
|
|
|
char buf[24];
|
2011-10-15 19:35:02 +00:00
|
|
|
int w, h, height, start_item, nb_eq_sliders[NB_SCREENS];
|
2009-12-09 07:25:46 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
viewportmanager_theme_enable(i, false, NULL);
|
2008-11-09 10:28:04 +00:00
|
|
|
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
FOR_NB_SCREENS(i) {
|
2009-01-05 07:50:25 +00:00
|
|
|
screens[i].set_viewport(NULL);
|
2007-02-19 02:14:51 +00:00
|
|
|
screens[i].setfont(FONT_SYSFIXED);
|
|
|
|
screens[i].clear_display();
|
2008-11-09 10:28:04 +00:00
|
|
|
|
|
|
|
/* Figure out how many sliders can be drawn on the screen */
|
|
|
|
screens[i].getstringsize("A", &w, &h);
|
|
|
|
|
|
|
|
/* Total height includes margins (1), text, slider, and line selector (1) */
|
|
|
|
height = 3 + h + 1 + SCROLLBAR_SIZE + 3;
|
|
|
|
nb_eq_sliders[i] = screens[i].lcdheight / height;
|
|
|
|
|
|
|
|
/* Make sure the "Edit Mode" text fits too */
|
|
|
|
height = nb_eq_sliders[i]*height + h + 2;
|
|
|
|
if (height > screens[i].lcdheight)
|
|
|
|
nb_eq_sliders[i]--;
|
|
|
|
|
2013-02-05 12:20:17 +00:00
|
|
|
if (nb_eq_sliders[i] > EQ_NUM_BANDS)
|
|
|
|
nb_eq_sliders[i] = EQ_NUM_BANDS;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
2008-11-09 10:28:04 +00:00
|
|
|
|
|
|
|
y = h + 1;
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2007-02-19 02:14:51 +00:00
|
|
|
/* Start off editing gain on the first band */
|
|
|
|
mode = GAIN;
|
|
|
|
current_band = 0;
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2007-02-19 02:14:51 +00:00
|
|
|
while (!exit_request) {
|
2008-11-09 10:28:04 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].clear_display();
|
|
|
|
|
|
|
|
/* Set pointer to the band data currently editable */
|
|
|
|
if (mode == GAIN) {
|
|
|
|
/* gain */
|
2012-03-09 21:38:33 +00:00
|
|
|
setting = &global_settings.eq_band_settings[current_band].gain;
|
2008-11-09 10:28:04 +00:00
|
|
|
|
|
|
|
step = EQ_GAIN_STEP;
|
|
|
|
fast_step = EQ_GAIN_FAST_STEP;
|
|
|
|
min = EQ_GAIN_MIN;
|
|
|
|
max = EQ_GAIN_MAX;
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2008-11-09 10:28:04 +00:00
|
|
|
snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
|
|
|
|
str(LANG_SYSFONT_GAIN), "(dB)");
|
|
|
|
|
|
|
|
screens[i].putsxy(0, 0, buf);
|
|
|
|
} else if (mode == CUTOFF) {
|
|
|
|
/* cutoff */
|
2012-03-09 21:38:33 +00:00
|
|
|
setting = &global_settings.eq_band_settings[current_band].cutoff;
|
2008-11-09 10:28:04 +00:00
|
|
|
|
|
|
|
step = EQ_CUTOFF_STEP;
|
|
|
|
fast_step = EQ_CUTOFF_FAST_STEP;
|
|
|
|
min = EQ_CUTOFF_MIN;
|
|
|
|
max = EQ_CUTOFF_MAX;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
|
|
|
|
str(LANG_SYSFONT_EQUALIZER_BAND_CUTOFF), "(Hz)");
|
|
|
|
|
|
|
|
screens[i].putsxy(0, 0, buf);
|
|
|
|
} else {
|
|
|
|
/* Q */
|
2012-03-09 21:38:33 +00:00
|
|
|
setting = &global_settings.eq_band_settings[current_band].q;
|
2008-11-09 10:28:04 +00:00
|
|
|
|
|
|
|
step = EQ_Q_STEP;
|
|
|
|
fast_step = EQ_Q_FAST_STEP;
|
|
|
|
min = EQ_Q_MIN;
|
|
|
|
max = EQ_Q_MAX;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
|
2014-01-16 16:08:37 +00:00
|
|
|
str(LANG_SYSFONT_EQUALIZER_BAND_Q), "");
|
2008-11-09 10:28:04 +00:00
|
|
|
|
|
|
|
screens[i].putsxy(0, 0, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw scrollbar if needed */
|
2013-02-05 12:20:17 +00:00
|
|
|
if (nb_eq_sliders[i] != EQ_NUM_BANDS)
|
2008-11-09 10:28:04 +00:00
|
|
|
{
|
|
|
|
if (current_band == 0) {
|
|
|
|
start_item = 0;
|
2013-01-22 18:08:16 +00:00
|
|
|
} else if (current_band == 9) {
|
2013-02-05 12:20:17 +00:00
|
|
|
start_item = EQ_NUM_BANDS - nb_eq_sliders[i];
|
2008-11-09 10:28:04 +00:00
|
|
|
} else {
|
|
|
|
start_item = current_band - 1;
|
|
|
|
}
|
|
|
|
x = SCROLLBAR_SIZE;
|
|
|
|
} else {
|
|
|
|
x = 1;
|
|
|
|
start_item = 0;
|
|
|
|
}
|
|
|
|
/* Draw equalizer band details */
|
|
|
|
draw_eq_sliders(&screens[i], x, y, nb_eq_sliders[i], start_item,
|
|
|
|
current_band, mode);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
|
|
|
screens[i].update();
|
|
|
|
}
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2007-02-19 02:14:51 +00:00
|
|
|
button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK);
|
|
|
|
|
|
|
|
switch (button) {
|
|
|
|
case ACTION_SETTINGS_DEC:
|
|
|
|
case ACTION_SETTINGS_DECREPEAT:
|
|
|
|
*(setting) -= step;
|
|
|
|
has_changed = true;
|
|
|
|
if (*(setting) < min)
|
|
|
|
*(setting) = min;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SETTINGS_INC:
|
|
|
|
case ACTION_SETTINGS_INCREPEAT:
|
|
|
|
*(setting) += step;
|
|
|
|
has_changed = true;
|
|
|
|
if (*(setting) > max)
|
|
|
|
*(setting) = max;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SETTINGS_INCBIGSTEP:
|
|
|
|
*(setting) += fast_step;
|
|
|
|
has_changed = true;
|
|
|
|
if (*(setting) > max)
|
|
|
|
*(setting) = max;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SETTINGS_DECBIGSTEP:
|
|
|
|
*(setting) -= fast_step;
|
|
|
|
has_changed = true;
|
|
|
|
if (*(setting) < min)
|
|
|
|
*(setting) = min;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_STD_PREV:
|
|
|
|
case ACTION_STD_PREVREPEAT:
|
|
|
|
current_band--;
|
|
|
|
if (current_band < 0)
|
2013-02-05 12:20:17 +00:00
|
|
|
current_band = EQ_NUM_BANDS - 1; /* wrap around */
|
2007-02-19 02:14:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_STD_NEXT:
|
|
|
|
case ACTION_STD_NEXTREPEAT:
|
2013-02-05 12:20:17 +00:00
|
|
|
current_band = (current_band + 1) % EQ_NUM_BANDS;
|
2007-02-19 02:14:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_STD_OK:
|
|
|
|
mode++;
|
|
|
|
if (mode > Q)
|
|
|
|
mode = GAIN; /* wrap around */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_STD_CANCEL:
|
|
|
|
exit_request = true;
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED) {
|
|
|
|
exit_request = true;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2007-02-19 02:14:51 +00:00
|
|
|
/* Update the filter if the user changed something */
|
|
|
|
if (has_changed) {
|
2011-08-21 21:18:09 +00:00
|
|
|
dsp_set_eq_coefs(current_band,
|
2012-03-27 23:52:15 +00:00
|
|
|
&global_settings.eq_band_settings[current_band]);
|
2007-02-19 02:14:51 +00:00
|
|
|
has_changed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset screen settings */
|
2013-02-05 12:20:17 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
2009-12-09 07:25:46 +00:00
|
|
|
{
|
2007-02-19 02:14:51 +00:00
|
|
|
screens[i].setfont(FONT_UI);
|
|
|
|
screens[i].clear_display();
|
2009-01-05 07:50:25 +00:00
|
|
|
screens[i].set_viewport(NULL);
|
2009-12-21 05:19:12 +00:00
|
|
|
viewportmanager_theme_undo(i, false);
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool eq_save_preset(void)
|
|
|
|
{
|
2007-12-07 10:59:07 +00:00
|
|
|
/* make sure that the eq is enabled for setting saving */
|
|
|
|
bool enabled = global_settings.eq_enabled;
|
|
|
|
global_settings.eq_enabled = true;
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2007-12-07 10:59:07 +00:00
|
|
|
bool result = settings_save_config(SETTINGS_SAVE_EQPRESET);
|
2013-02-05 12:20:17 +00:00
|
|
|
|
2007-12-07 10:59:07 +00:00
|
|
|
global_settings.eq_enabled = enabled;
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2007-12-07 10:59:07 +00:00
|
|
|
return result;
|
2007-02-19 02:14:51 +00:00
|
|
|
}
|
|
|
|
/* Allows browsing of preset files */
|
2010-07-25 18:28:42 +00:00
|
|
|
static struct browse_folder_info eqs = { EQS_DIR, SHOW_CFG };
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(eq_graphical, 0, ID2P(LANG_EQUALIZER_GRAPHICAL),
|
2013-02-05 12:20:17 +00:00
|
|
|
(int(*)(void))eq_menu_graphical, NULL, lowlatency_callback,
|
2007-03-03 13:52:14 +00:00
|
|
|
Icon_EQ);
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(eq_save, 0, ID2P(LANG_EQUALIZER_SAVE),
|
2007-03-18 07:03:43 +00:00
|
|
|
(int(*)(void))eq_save_preset, NULL, NULL, Icon_NOICON);
|
2010-07-25 18:28:42 +00:00
|
|
|
MENUITEM_FUNCTION(eq_browse, MENU_FUNC_USEPARAM, ID2P(LANG_EQUALIZER_BROWSE),
|
|
|
|
browse_folder, (void*)&eqs, lowlatency_callback,
|
2008-03-30 09:31:09 +00:00
|
|
|
Icon_NOICON);
|
2007-02-19 02:14:51 +00:00
|
|
|
|
2008-03-30 09:31:09 +00:00
|
|
|
MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), NULL, Icon_EQ,
|
2013-02-05 12:20:17 +00:00
|
|
|
&eq_enable, &eq_graphical, &eq_precut, &gain_menu,
|
|
|
|
&advanced_menu, &eq_save, &eq_browse);
|
2007-02-19 02:14:51 +00:00
|
|
|
|