summaryrefslogtreecommitdiff
path: root/apps/menus/eq_menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/menus/eq_menu.c')
-rw-r--r--apps/menus/eq_menu.c552
1 files changed, 314 insertions, 238 deletions
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 @@
27#include "system.h" 27#include "system.h"
28#include "kernel.h" 28#include "kernel.h"
29#include "lcd.h" 29#include "lcd.h"
30#include "list.h"
30#include "menu.h" 31#include "menu.h"
31#include "action.h" 32#include "action.h"
32#include "mp3_playback.h" 33#include "mp3_playback.h"
@@ -46,6 +47,8 @@
46#include "menu_common.h" 47#include "menu_common.h"
47#include "viewport.h" 48#include "viewport.h"
48#include "exported_menus.h" 49#include "exported_menus.h"
50#include "pcmbuf.h"
51#include "option_select.h"
49 52
50/* 53/*
51 * Utility functions 54 * Utility functions
@@ -70,8 +73,8 @@ const char* eq_precut_format(char* buffer, size_t buffer_size, int value, const
70 */ 73 */
71static void eq_apply(void) 74static void eq_apply(void)
72{ 75{
73 dsp_eq_enable(global_settings.eq_enabled); 76 dsp_eq_enable(global_settings.eq_enabled);
74 dsp_set_eq_precut(global_settings.eq_precut); 77 dsp_set_eq_precut(global_settings.eq_precut);
75 /* Update all bands */ 78 /* Update all bands */
76 for(int i = 0; i < EQ_NUM_BANDS; i++) { 79 for(int i = 0; i < EQ_NUM_BANDS; i++) {
77 dsp_set_eq_coefs(i, &global_settings.eq_band_settings[i]); 80 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)
96MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, eq_setting_callback); 99MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, eq_setting_callback);
97MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, eq_setting_callback); 100MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, eq_setting_callback);
98 101
99MENUITEM_SETTING(cutoff_0, &global_settings.eq_band_settings[0].cutoff, 102static char* gainitem_get_name(int selected_item, void *data, char *buffer, size_t len)
100 eq_setting_callback);
101MENUITEM_SETTING(cutoff_1, &global_settings.eq_band_settings[1].cutoff,
102 eq_setting_callback);
103MENUITEM_SETTING(cutoff_2, &global_settings.eq_band_settings[2].cutoff,
104 eq_setting_callback);
105MENUITEM_SETTING(cutoff_3, &global_settings.eq_band_settings[3].cutoff,
106 eq_setting_callback);
107MENUITEM_SETTING(cutoff_4, &global_settings.eq_band_settings[4].cutoff,
108 eq_setting_callback);
109MENUITEM_SETTING(cutoff_5, &global_settings.eq_band_settings[5].cutoff,
110 eq_setting_callback);
111MENUITEM_SETTING(cutoff_6, &global_settings.eq_band_settings[6].cutoff,
112 eq_setting_callback);
113MENUITEM_SETTING(cutoff_7, &global_settings.eq_band_settings[7].cutoff,
114 eq_setting_callback);
115MENUITEM_SETTING(cutoff_8, &global_settings.eq_band_settings[8].cutoff,
116 eq_setting_callback);
117MENUITEM_SETTING(cutoff_9, &global_settings.eq_band_settings[9].cutoff,
118 eq_setting_callback);
119
120MENUITEM_SETTING(q_0, &global_settings.eq_band_settings[0].q,
121 eq_setting_callback);
122MENUITEM_SETTING(q_1, &global_settings.eq_band_settings[1].q,
123 eq_setting_callback);
124MENUITEM_SETTING(q_2, &global_settings.eq_band_settings[2].q,
125 eq_setting_callback);
126MENUITEM_SETTING(q_3, &global_settings.eq_band_settings[3].q,
127 eq_setting_callback);
128MENUITEM_SETTING(q_4, &global_settings.eq_band_settings[4].q,
129 eq_setting_callback);
130MENUITEM_SETTING(q_5, &global_settings.eq_band_settings[5].q,
131 eq_setting_callback);
132MENUITEM_SETTING(q_6, &global_settings.eq_band_settings[6].q,
133 eq_setting_callback);
134MENUITEM_SETTING(q_7, &global_settings.eq_band_settings[7].q,
135 eq_setting_callback);
136MENUITEM_SETTING(q_8, &global_settings.eq_band_settings[8].q,
137 eq_setting_callback);
138MENUITEM_SETTING(q_9, &global_settings.eq_band_settings[9].q,
139 eq_setting_callback);
140
141MENUITEM_SETTING(gain_0, &global_settings.eq_band_settings[0].gain,
142 eq_setting_callback);
143MENUITEM_SETTING(gain_1, &global_settings.eq_band_settings[1].gain,
144 eq_setting_callback);
145MENUITEM_SETTING(gain_2, &global_settings.eq_band_settings[2].gain,
146 eq_setting_callback);
147MENUITEM_SETTING(gain_3, &global_settings.eq_band_settings[3].gain,
148 eq_setting_callback);
149MENUITEM_SETTING(gain_4, &global_settings.eq_band_settings[4].gain,
150 eq_setting_callback);
151MENUITEM_SETTING(gain_5, &global_settings.eq_band_settings[5].gain,
152 eq_setting_callback);
153MENUITEM_SETTING(gain_6, &global_settings.eq_band_settings[6].gain,
154 eq_setting_callback);
155MENUITEM_SETTING(gain_7, &global_settings.eq_band_settings[7].gain,
156 eq_setting_callback);
157MENUITEM_SETTING(gain_8, &global_settings.eq_band_settings[8].gain,
158 eq_setting_callback);
159MENUITEM_SETTING(gain_9, &global_settings.eq_band_settings[9].gain,
160 eq_setting_callback);
161
162static char* gainitem_get_name(int selected_item, void * data, char *buffer)
163{ 103{
164 (void)selected_item; 104 (void)data;
165 int *setting = (int*)data; 105 snprintf(buffer, len, str(LANG_EQUALIZER_GAIN_ITEM),
166 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_GAIN_ITEM), *setting); 106 global_settings.eq_band_settings[selected_item].cutoff);
107
167 return buffer; 108 return buffer;
168} 109}
169 110
170static int gainitem_speak_item(int selected_item, void * data) 111static int gainitem_speak_item(int selected_item, void *data)
171{ 112{
172 (void)selected_item; 113 (void)data;
173 int *setting = (int*)data; 114 talk_number(global_settings.eq_band_settings[selected_item].cutoff, false);
174 talk_number(*setting, false);
175 talk_id(LANG_EQUALIZER_GAIN_ITEM, true); 115 talk_id(LANG_EQUALIZER_GAIN_ITEM, true);
176 return 0; 116 return 0;
177} 117}
178 118
179static int do_option(void * param) 119static enum themable_icons gainitem_get_icon(int selected_item, void * data)
180{ 120{
181 const struct menu_item_ex *setting = (const struct menu_item_ex*)param; 121 (void)selected_item;
182 lowlatency_callback(ACTION_ENTER_MENUITEM, setting); 122 (void)data;
183 do_setting_from_menu(setting, NULL); 123
184 eq_apply(); 124 return Icon_Menu_functioncall;
185 lowlatency_callback(ACTION_EXIT_MENUITEM, setting);
186 return 0;
187} 125}
188 126
189MENUITEM_FUNCTION_DYNTEXT(gain_item_0, MENU_FUNC_USEPARAM, 127static const char* db_format(char* buffer, size_t buffer_size, int value,
190 do_option, (void*)&gain_0, 128 const char* unit)
191 gainitem_get_name, gainitem_speak_item, 129{
192 &global_settings.eq_band_settings[0].cutoff, 130 int v = abs(value);
193 NULL, Icon_NOICON); 131
194MENUITEM_FUNCTION_DYNTEXT(gain_item_1, MENU_FUNC_USEPARAM, 132 snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "",
195 do_option, (void*)&gain_1, 133 v / 10, v % 10, unit);
196 gainitem_get_name, gainitem_speak_item, 134 return buffer;
197 &global_settings.eq_band_settings[1].cutoff, 135}
198 NULL, Icon_NOICON); 136
199MENUITEM_FUNCTION_DYNTEXT(gain_item_2, MENU_FUNC_USEPARAM, 137static int32_t get_dec_talkid(int value, int unit)
200 do_option, (void*)&gain_2, 138{
201 gainitem_get_name, gainitem_speak_item, 139 return TALK_ID_DECIMAL(value, 1, unit);
202 &global_settings.eq_band_settings[2].cutoff, 140}
203 NULL, Icon_NOICON); 141
204MENUITEM_FUNCTION_DYNTEXT(gain_item_3, MENU_FUNC_USEPARAM, 142static const struct int_setting gain_int_setting = {
205 do_option, (void*)&gain_3, 143 .option_callback = NULL,
206 gainitem_get_name, gainitem_speak_item, 144 .unit = UNIT_DB,
207 &global_settings.eq_band_settings[3].cutoff, 145 .min = EQ_GAIN_MIN,
208 NULL, Icon_NOICON); 146 .max = EQ_GAIN_MAX,
209MENUITEM_FUNCTION_DYNTEXT(gain_item_4, MENU_FUNC_USEPARAM, 147 .step = EQ_GAIN_STEP,
210 do_option, (void*)&gain_4, 148 .formatter = db_format,
211 gainitem_get_name, gainitem_speak_item, 149 .get_talk_id = get_dec_talkid,
212 &global_settings.eq_band_settings[4].cutoff, 150};
213 NULL, Icon_NOICON); 151
214MENUITEM_FUNCTION_DYNTEXT(gain_item_5, MENU_FUNC_USEPARAM, 152static const struct int_setting q_int_setting = {
215 do_option, (void*)&gain_5, 153 .option_callback = NULL,
216 gainitem_get_name, gainitem_speak_item, 154 .unit = UNIT_INT,
217 &global_settings.eq_band_settings[5].cutoff, 155 .min = EQ_Q_MIN,
218 NULL, Icon_NOICON); 156 .max = EQ_Q_MAX,
219MENUITEM_FUNCTION_DYNTEXT(gain_item_6, MENU_FUNC_USEPARAM, 157 .step = EQ_Q_STEP,
220 do_option, (void*)&gain_6, 158 .formatter = eq_q_format,
221 gainitem_get_name, gainitem_speak_item, 159 .get_talk_id = get_dec_talkid,
222 &global_settings.eq_band_settings[6].cutoff, 160};
223 NULL, Icon_NOICON); 161
224MENUITEM_FUNCTION_DYNTEXT(gain_item_7, MENU_FUNC_USEPARAM, 162static const struct int_setting cutoff_int_setting = {
225 do_option, (void*)&gain_7, 163 .option_callback = NULL,
226 gainitem_get_name, gainitem_speak_item, 164 .unit = UNIT_HERTZ,
227 &global_settings.eq_band_settings[7].cutoff, 165 .min = EQ_CUTOFF_MIN,
228 NULL, Icon_NOICON); 166 .max = EQ_CUTOFF_MAX,
229MENUITEM_FUNCTION_DYNTEXT(gain_item_8, MENU_FUNC_USEPARAM, 167 .step = EQ_CUTOFF_STEP,
230 do_option, (void*)&gain_8, 168 .formatter = NULL,
231 gainitem_get_name, gainitem_speak_item, 169 .get_talk_id = NULL,
232 &global_settings.eq_band_settings[8].cutoff,
233 NULL, Icon_NOICON);
234MENUITEM_FUNCTION_DYNTEXT(gain_item_9, MENU_FUNC_USEPARAM,
235 do_option, (void*)&gain_9,
236 gainitem_get_name, gainitem_speak_item,
237 &global_settings.eq_band_settings[9].cutoff,
238 NULL, Icon_NOICON);
239
240MAKE_MENU(gain_menu, ID2P(LANG_EQUALIZER_GAIN), NULL, Icon_NOICON, &gain_item_0,
241 &gain_item_1, &gain_item_2, &gain_item_3, &gain_item_4,
242 &gain_item_5, &gain_item_6, &gain_item_7, &gain_item_8,
243 &gain_item_9);
244
245static const struct menu_item_ex *band_items[8][3] = {
246 { &cutoff_1, &q_1, &gain_1 },
247 { &cutoff_2, &q_2, &gain_2 },
248 { &cutoff_3, &q_3, &gain_3 },
249 { &cutoff_4, &q_4, &gain_4 },
250 { &cutoff_5, &q_5, &gain_5 },
251 { &cutoff_6, &q_6, &gain_6 },
252 { &cutoff_7, &q_7, &gain_7 },
253 { &cutoff_8, &q_8, &gain_8 }
254}; 170};
255 171
256static char* centerband_get_name(int selected_item, void * data, char *buffer) 172static int simplelist_action_callback(int action, struct gui_synclist *lists)
257{ 173{
258 (void)selected_item; 174 (void)lists;
259 int band = (intptr_t)data; 175 if (action == ACTION_STD_OK)
260 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band); 176 return ACTION_STD_CANCEL;
261 return buffer; 177 return action;
262} 178}
263 179
264static int centerband_speak_item(int selected_item, void * data) 180static int eq_do_simple_menu(void * param)
265{ 181{
266 (void)selected_item; 182 (void)param;
267 int band = (intptr_t)data; 183 struct simplelist_info info;
268 talk_id(LANG_EQUALIZER_BAND_PEAK, false); 184 struct settings_list setting;
269 talk_number(band, true); 185 char title[MAX_PATH];
186
187 simplelist_info_init(&info, str(LANG_EQUALIZER_GAIN), EQ_NUM_BANDS, NULL);
188 info.get_name = (list_get_name*)gainitem_get_name;
189 info.get_talk = gainitem_speak_item;
190 info.get_icon = gainitem_get_icon;
191 info.action_callback = simplelist_action_callback;
192 info.selection = -1;
193 info.title_icon = Icon_Submenu;
194 setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP;
195 setting.lang_id = LANG_GAIN;
196 setting.default_val.int_ = 0;
197 setting.int_setting = &gain_int_setting;
198
199 while (true)
200 {
201 simplelist_show_list(&info);
202 if (info.selection < 0)
203 break;
204 pcmbuf_set_low_latency(true);
205 setting.setting = &global_settings.eq_band_settings[info.selection].gain;
206 option_screen(&setting, NULL, false,
207 gainitem_get_name(info.selection, NULL, title, MAX_PATH));
208 eq_apply();
209 pcmbuf_set_low_latency(false);
210 }
270 return 0; 211 return 0;
271} 212}
213MENUITEM_FUNCTION(gain_menu, 0, ID2P(LANG_EQUALIZER_GAIN), eq_do_simple_menu,
214 NULL, NULL, Icon_Submenu);
272 215
273static int do_center_band_menu(void* param) 216static void selection_to_banditem(int selection, int expanded_band, int *band, int *item)
274{ 217{
275 int band = (intptr_t)param; 218 int diff = selection - expanded_band;
276 struct menu_item_ex menu; 219
277 struct menu_callback_with_desc cb_and_desc; 220 if (expanded_band < 0 || diff < 0)
278 char desc[MAX_PATH]; 221 {
279 222 *item = 0;
280 cb_and_desc.menu_callback = NULL; 223 *band = selection;
281 snprintf(desc, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band); 224 }
282 cb_and_desc.desc = desc; 225 else if (diff < 4)
283 cb_and_desc.icon_id = Icon_EQ; 226 {
284 menu.flags = MT_MENU|(3<<MENU_COUNT_SHIFT)|MENU_HAS_DESC; 227 *item = selection - expanded_band;
285 menu.submenus = band_items[band-1]; 228 *band = expanded_band;
286 menu.callback_and_desc = &cb_and_desc; 229 }
287 do_menu(&menu, NULL, NULL, false); 230 else
288 return 0; 231 {
232 *item = 0;
233 *band = expanded_band + diff - 3;
234 }
289} 235}
290 236
291MAKE_MENU(band_0_menu, ID2P(LANG_EQUALIZER_BAND_LOW_SHELF), NULL, 237static char *advancedmenu_item_get_name(int selected_item, void *data, char *buffer, size_t len)
292 Icon_EQ, &cutoff_0, &q_0, &gain_0); 238{
293MENUITEM_FUNCTION_DYNTEXT(band_1_menu, MENU_FUNC_USEPARAM, 239 (void)len;
294 do_center_band_menu, (void*)1, 240 int band;
295 centerband_get_name, centerband_speak_item, 241 int item;
296 (void*)1, NULL, Icon_EQ); 242 char *lang = NULL;
297MENUITEM_FUNCTION_DYNTEXT(band_2_menu, MENU_FUNC_USEPARAM,
298 do_center_band_menu, (void*)2,
299 centerband_get_name, centerband_speak_item,
300 (void*)2, NULL, Icon_EQ);
301MENUITEM_FUNCTION_DYNTEXT(band_3_menu, MENU_FUNC_USEPARAM,
302 do_center_band_menu, (void*)3,
303 centerband_get_name, centerband_speak_item,
304 (void*)3, NULL, Icon_EQ);
305MENUITEM_FUNCTION_DYNTEXT(band_4_menu, MENU_FUNC_USEPARAM,
306 do_center_band_menu, (void*)4,
307 centerband_get_name, centerband_speak_item,
308 (void*)4, NULL, Icon_EQ);
309MENUITEM_FUNCTION_DYNTEXT(band_5_menu, MENU_FUNC_USEPARAM,
310 do_center_band_menu, (void*)5,
311 centerband_get_name, centerband_speak_item,
312 (void*)5, NULL, Icon_EQ);
313MENUITEM_FUNCTION_DYNTEXT(band_6_menu, MENU_FUNC_USEPARAM,
314 do_center_band_menu, (void*)6,
315 centerband_get_name, centerband_speak_item,
316 (void*)6, NULL, Icon_EQ);
317MENUITEM_FUNCTION_DYNTEXT(band_7_menu, MENU_FUNC_USEPARAM,
318 do_center_band_menu, (void*)7,
319 centerband_get_name, centerband_speak_item,
320 (void*)7, NULL, Icon_EQ);
321MENUITEM_FUNCTION_DYNTEXT(band_8_menu, MENU_FUNC_USEPARAM,
322 do_center_band_menu, (void*)8,
323 centerband_get_name, centerband_speak_item,
324 (void*)8, NULL, Icon_EQ);
325MAKE_MENU(band_9_menu, ID2P(LANG_EQUALIZER_BAND_HIGH_SHELF), NULL,
326 Icon_EQ, &cutoff_9, &q_9, &gain_9);
327
328MAKE_MENU(advanced_eq_menu_, ID2P(LANG_EQUALIZER_ADVANCED), NULL, Icon_EQ,
329 &band_0_menu, &band_1_menu, &band_2_menu, &band_3_menu, &band_4_menu,
330 &band_5_menu, &band_6_menu, &band_7_menu, &band_8_menu, &band_9_menu);
331 243
244 selection_to_banditem(selected_item, *(intptr_t*)data, &band, &item);
245
246 strcpy(buffer, "\t");
247 switch (item)
248 {
249 case 0: /* Band title */
250 if (band == 0)
251 return str(LANG_EQUALIZER_BAND_LOW_SHELF);
252 else if (band == EQ_NUM_BANDS - 1)
253 return str(LANG_EQUALIZER_BAND_HIGH_SHELF);
254 else
255 {
256 snprintf(buffer, MAX_PATH, str(LANG_EQUALIZER_BAND_PEAK), band);
257 return buffer;
258 }
259 break;
260 case 1: /* cutoff */
261 if (band == 0)
262 lang = str(LANG_EQUALIZER_BAND_CUTOFF);
263 else if (band == EQ_NUM_BANDS - 1)
264 lang = str(LANG_EQUALIZER_BAND_CUTOFF);
265 else
266 lang = str(LANG_EQUALIZER_BAND_CENTER);
267 break;
268 case 2: /* Q */
269 lang = str(LANG_EQUALIZER_BAND_Q);
270 break;
271 case 3: /* Gain */
272 lang = str(LANG_GAIN);
273 break;
274 }
275
276 return strcat(buffer, lang);;
277}
278
279static int advancedmenu_speak_item(int selected_item, void *data)
280{
281 (void)data;
282 int band;
283 int item;
284 int lang = -1;
285
286 selection_to_banditem(selected_item, *(intptr_t*)data, &band, &item);
287
288 switch (item)
289 {
290 case 0: /* Band title */
291 if (band == 0)
292 lang = LANG_EQUALIZER_BAND_LOW_SHELF;
293 else if (band == EQ_NUM_BANDS - 1)
294 lang = LANG_EQUALIZER_BAND_HIGH_SHELF;
295 else
296 {
297 talk_id(LANG_EQUALIZER_BAND_PEAK, false);
298 talk_number(band, true);
299 return -1;
300 }
301 break;
302 case 1: /* cutoff */
303 if (band == 0)
304 lang = LANG_EQUALIZER_BAND_CUTOFF;
305 else if (band == EQ_NUM_BANDS - 1)
306 lang = LANG_EQUALIZER_BAND_CUTOFF;
307 else
308 lang = LANG_EQUALIZER_BAND_CENTER;
309 break;
310 case 2: /* Q */
311 lang = LANG_EQUALIZER_BAND_Q;
312 break;
313 case 3: /* Gain */
314 lang = LANG_GAIN;
315 break;
316 }
317 talk_id(lang, true);
318 return -1;
319}
320
321static enum themable_icons advancedmenu_get_icon(int selected_item, void * data)
322{
323 (void)data;
324 int band;
325 int item;
326
327 selection_to_banditem(selected_item, *(intptr_t*)data, &band, &item);
328
329 if (item == 0)
330 return Icon_Submenu;
331 else
332 return Icon_Menu_setting;
333}
334extern struct eq_band_setting eq_defaults[EQ_NUM_BANDS];
335
336static int eq_do_advanced_menu(void * param)
337{
338 (void)param;
339 struct simplelist_info info;
340 struct settings_list setting;
341 char title[MAX_PATH];
342 int band, item;
343 intptr_t selected_band = -1;
344
345 simplelist_info_init(&info, str(LANG_EQUALIZER_ADVANCED),
346 EQ_NUM_BANDS, &selected_band);
347 info.get_name = (list_get_name*)advancedmenu_item_get_name;
348 info.get_talk = advancedmenu_speak_item;
349 info.get_icon = advancedmenu_get_icon;
350 info.action_callback = simplelist_action_callback;
351 info.selection = -1;
352 info.title_icon = Icon_EQ;
353 setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP;
354
355 while (true)
356 {
357 simplelist_show_list(&info);
358 if (info.selection < 0)
359 break;
360 selection_to_banditem(info.selection, selected_band, &band, &item);
361 switch (item)
362 {
363 case 0: /* title, do nothing */
364 {
365 int extra;
366 if (selected_band == band)
367 {
368 extra = 0;
369 selected_band = -1;
370 }
371 else
372 {
373 extra = 3;
374 selected_band = band;
375 }
376 info.selection = band;
377 info.count = EQ_NUM_BANDS + extra;
378 continue;
379 }
380 case 1: /* cutoff */
381 if (band == 0 || band == EQ_NUM_BANDS - 1)
382 setting.lang_id = LANG_EQUALIZER_BAND_CUTOFF;
383 else
384 setting.lang_id = LANG_EQUALIZER_BAND_CENTER;
385 setting.default_val.int_ = eq_defaults[band].cutoff;
386 setting.int_setting = &cutoff_int_setting;
387 break;
388 case 2: /* Q */
389 setting.lang_id = LANG_EQUALIZER_BAND_Q;
390 setting.default_val.int_ = eq_defaults[band].q;
391 setting.int_setting = &q_int_setting;
392 break;
393 case 3: /* Gain */
394 setting.lang_id = LANG_GAIN;
395 setting.default_val.int_ = eq_defaults[band].gain;
396 setting.int_setting = &gain_int_setting;
397 break;
398 }
399 pcmbuf_set_low_latency(true);
400 setting.setting = &global_settings.eq_band_settings[band].gain;
401 advancedmenu_item_get_name(info.selection, &selected_band, title, MAX_PATH);
402
403 option_screen(&setting, NULL, false, title[0] == '\t' ? &title[1] : title);
404 eq_apply();
405 pcmbuf_set_low_latency(false);
406 }
407 return 0;
408}
409MENUITEM_FUNCTION(advanced_menu, 0, ID2P(LANG_EQUALIZER_ADVANCED),
410 eq_do_advanced_menu, NULL, NULL, Icon_EQ);
332 411
333enum eq_slider_mode { 412enum eq_slider_mode {
334 GAIN, 413 GAIN,
@@ -361,12 +440,12 @@ static int draw_eq_slider(struct screen * screen, int x, int y,
361 steps = EQ_Q_MAX - EQ_Q_MIN; 440 steps = EQ_Q_MAX - EQ_Q_MIN;
362 min_item = q - EQ_Q_STEP - EQ_Q_MIN; 441 min_item = q - EQ_Q_STEP - EQ_Q_MIN;
363 max_item = q + EQ_Q_STEP - EQ_Q_MIN; 442 max_item = q + EQ_Q_STEP - EQ_Q_MIN;
364 break; 443 break;
365 case CUTOFF: 444 case CUTOFF:
366 steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN; 445 steps = EQ_CUTOFF_MAX - EQ_CUTOFF_MIN;
367 min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2; 446 min_item = cutoff - EQ_CUTOFF_FAST_STEP * 2;
368 max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2; 447 max_item = cutoff + EQ_CUTOFF_FAST_STEP * 2;
369 break; 448 break;
370 case GAIN: 449 case GAIN:
371 default: 450 default:
372 steps = EQ_GAIN_MAX - EQ_GAIN_MIN; 451 steps = EQ_GAIN_MAX - EQ_GAIN_MIN;
@@ -383,7 +462,7 @@ static int draw_eq_slider(struct screen * screen, int x, int y,
383 if (band == 0) { 462 if (band == 0) {
384 screen->putsxy(x1, y1, "LS: "); 463 screen->putsxy(x1, y1, "LS: ");
385 screen->getstringsize("LS:", &w, &h); 464 screen->getstringsize("LS:", &w, &h);
386 } else if (band == 9) { 465 } else if (band == EQ_NUM_BANDS - 1) {
387 screen->putsxy(x1, y1, "HS: "); 466 screen->putsxy(x1, y1, "HS: ");
388 screen->getstringsize("HS:", &w, &h); 467 screen->getstringsize("HS:", &w, &h);
389 } else { 468 } else {
@@ -425,7 +504,7 @@ static int draw_eq_slider(struct screen * screen, int x, int y,
425 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID); 504 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
426 else 505 else
427 screen->set_drawmode(DRMODE_SOLID); 506 screen->set_drawmode(DRMODE_SOLID);
428 507
429 snprintf(buf, sizeof(buf), "%5d%s", cutoff, 508 snprintf(buf, sizeof(buf), "%5d%s", cutoff,
430 screen->lcdwidth >= 160 ? "Hz" : ""); 509 screen->lcdwidth >= 160 ? "Hz" : "");
431 screen->getstringsize(buf, &w, &h); 510 screen->getstringsize(buf, &w, &h);
@@ -453,9 +532,9 @@ static void draw_eq_sliders(struct screen * screen, int x, int y,
453{ 532{
454 int height = y; 533 int height = y;
455 534
456 start_item = MIN(start_item, 10 - nb_eq_sliders); 535 start_item = MIN(start_item, EQ_NUM_BANDS - nb_eq_sliders);
457 536
458 for (int i = 0; i < 10; i++) { 537 for (int i = 0; i < EQ_NUM_BANDS; i++) {
459 struct eq_band_setting *setting = &global_settings.eq_band_settings[i]; 538 struct eq_band_setting *setting = &global_settings.eq_band_settings[i];
460 int cutoff = setting->cutoff; 539 int cutoff = setting->cutoff;
461 int q = setting->q; 540 int q = setting->q;
@@ -473,9 +552,9 @@ static void draw_eq_sliders(struct screen * screen, int x, int y,
473 } 552 }
474 } 553 }
475 554
476 if (nb_eq_sliders != 10) 555 if (nb_eq_sliders != EQ_NUM_BANDS)
477 gui_scrollbar_draw(screen, 0, y, SCROLLBAR_SIZE - 1, 556 gui_scrollbar_draw(screen, 0, y, SCROLLBAR_SIZE - 1,
478 screen->lcdheight - y, 10, 557 screen->lcdheight - y, EQ_NUM_BANDS,
479 start_item, start_item + nb_eq_sliders, 558 start_item, start_item + nb_eq_sliders,
480 VERTICAL); 559 VERTICAL);
481 return; 560 return;
@@ -514,16 +593,16 @@ bool eq_menu_graphical(void)
514 if (height > screens[i].lcdheight) 593 if (height > screens[i].lcdheight)
515 nb_eq_sliders[i]--; 594 nb_eq_sliders[i]--;
516 595
517 if (nb_eq_sliders[i] > 10) 596 if (nb_eq_sliders[i] > EQ_NUM_BANDS)
518 nb_eq_sliders[i] = 10; 597 nb_eq_sliders[i] = EQ_NUM_BANDS;
519 } 598 }
520 599
521 y = h + 1; 600 y = h + 1;
522 601
523 /* Start off editing gain on the first band */ 602 /* Start off editing gain on the first band */
524 mode = GAIN; 603 mode = GAIN;
525 current_band = 0; 604 current_band = 0;
526 605
527 while (!exit_request) { 606 while (!exit_request) {
528 FOR_NB_SCREENS(i) 607 FOR_NB_SCREENS(i)
529 { 608 {
@@ -538,7 +617,7 @@ bool eq_menu_graphical(void)
538 fast_step = EQ_GAIN_FAST_STEP; 617 fast_step = EQ_GAIN_FAST_STEP;
539 min = EQ_GAIN_MIN; 618 min = EQ_GAIN_MIN;
540 max = EQ_GAIN_MAX; 619 max = EQ_GAIN_MAX;
541 620
542 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE), 621 snprintf(buf, sizeof(buf), str(LANG_SYSFONT_EQUALIZER_EDIT_MODE),
543 str(LANG_SYSFONT_GAIN), "(dB)"); 622 str(LANG_SYSFONT_GAIN), "(dB)");
544 623
@@ -572,12 +651,12 @@ bool eq_menu_graphical(void)
572 } 651 }
573 652
574 /* Draw scrollbar if needed */ 653 /* Draw scrollbar if needed */
575 if (nb_eq_sliders[i] != 10) 654 if (nb_eq_sliders[i] != EQ_NUM_BANDS)
576 { 655 {
577 if (current_band == 0) { 656 if (current_band == 0) {
578 start_item = 0; 657 start_item = 0;
579 } else if (current_band == 9) { 658 } else if (current_band == 9) {
580 start_item = 10 - nb_eq_sliders[i]; 659 start_item = EQ_NUM_BANDS - nb_eq_sliders[i];
581 } else { 660 } else {
582 start_item = current_band - 1; 661 start_item = current_band - 1;
583 } 662 }
@@ -592,7 +671,7 @@ bool eq_menu_graphical(void)
592 671
593 screens[i].update(); 672 screens[i].update();
594 } 673 }
595 674
596 button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK); 675 button = get_action(CONTEXT_SETTINGS_EQ,TIMEOUT_BLOCK);
597 676
598 switch (button) { 677 switch (button) {
@@ -630,14 +709,12 @@ bool eq_menu_graphical(void)
630 case ACTION_STD_PREVREPEAT: 709 case ACTION_STD_PREVREPEAT:
631 current_band--; 710 current_band--;
632 if (current_band < 0) 711 if (current_band < 0)
633 current_band = 9; /* wrap around */ 712 current_band = EQ_NUM_BANDS - 1; /* wrap around */
634 break; 713 break;
635 714
636 case ACTION_STD_NEXT: 715 case ACTION_STD_NEXT:
637 case ACTION_STD_NEXTREPEAT: 716 case ACTION_STD_NEXTREPEAT:
638 current_band++; 717 current_band = (current_band + 1) % EQ_NUM_BANDS;
639 if (current_band > 9)
640 current_band = 0; /* wrap around */
641 break; 718 break;
642 719
643 case ACTION_STD_OK: 720 case ACTION_STD_OK:
@@ -657,7 +734,7 @@ bool eq_menu_graphical(void)
657 } 734 }
658 break; 735 break;
659 } 736 }
660 737
661 /* Update the filter if the user changed something */ 738 /* Update the filter if the user changed something */
662 if (has_changed) { 739 if (has_changed) {
663 dsp_set_eq_coefs(current_band, 740 dsp_set_eq_coefs(current_band,
@@ -667,7 +744,7 @@ bool eq_menu_graphical(void)
667 } 744 }
668 745
669 /* Reset screen settings */ 746 /* Reset screen settings */
670 FOR_NB_SCREENS(i) 747 FOR_NB_SCREENS(i)
671 { 748 {
672 screens[i].setfont(FONT_UI); 749 screens[i].setfont(FONT_UI);
673 screens[i].clear_display(); 750 screens[i].clear_display();
@@ -682,19 +759,18 @@ static bool eq_save_preset(void)
682 /* make sure that the eq is enabled for setting saving */ 759 /* make sure that the eq is enabled for setting saving */
683 bool enabled = global_settings.eq_enabled; 760 bool enabled = global_settings.eq_enabled;
684 global_settings.eq_enabled = true; 761 global_settings.eq_enabled = true;
685 762
686 bool result = settings_save_config(SETTINGS_SAVE_EQPRESET); 763 bool result = settings_save_config(SETTINGS_SAVE_EQPRESET);
687 764
688 global_settings.eq_enabled = enabled; 765 global_settings.eq_enabled = enabled;
689 766
690 return result; 767 return result;
691} 768}
692
693/* Allows browsing of preset files */ 769/* Allows browsing of preset files */
694static struct browse_folder_info eqs = { EQS_DIR, SHOW_CFG }; 770static struct browse_folder_info eqs = { EQS_DIR, SHOW_CFG };
695 771
696MENUITEM_FUNCTION(eq_graphical, 0, ID2P(LANG_EQUALIZER_GRAPHICAL), 772MENUITEM_FUNCTION(eq_graphical, 0, ID2P(LANG_EQUALIZER_GRAPHICAL),
697 (int(*)(void))eq_menu_graphical, NULL, lowlatency_callback, 773 (int(*)(void))eq_menu_graphical, NULL, lowlatency_callback,
698 Icon_EQ); 774 Icon_EQ);
699MENUITEM_FUNCTION(eq_save, 0, ID2P(LANG_EQUALIZER_SAVE), 775MENUITEM_FUNCTION(eq_save, 0, ID2P(LANG_EQUALIZER_SAVE),
700 (int(*)(void))eq_save_preset, NULL, NULL, Icon_NOICON); 776 (int(*)(void))eq_save_preset, NULL, NULL, Icon_NOICON);
@@ -703,6 +779,6 @@ MENUITEM_FUNCTION(eq_browse, MENU_FUNC_USEPARAM, ID2P(LANG_EQUALIZER_BROWSE),
703 Icon_NOICON); 779 Icon_NOICON);
704 780
705MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), NULL, Icon_EQ, 781MAKE_MENU(equalizer_menu, ID2P(LANG_EQUALIZER), NULL, Icon_EQ,
706 &eq_enable, &eq_graphical, &eq_precut, &gain_menu, 782 &eq_enable, &eq_graphical, &eq_precut, &gain_menu,
707 &advanced_eq_menu_, &eq_save, &eq_browse); 783 &advanced_menu, &eq_save, &eq_browse);
708 784