blob: 1027d6a0b88e4b69e6524d8f6956a941ba191eab [file] [log] [blame]
Michael Sevakis80d0d152010-05-15 13:09:45 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Michael Sevakis
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include "config.h"
23#include "sound.h"
24#include "settings.h"
25#include "lang.h"
26#include "menu.h"
27#include "talk.h"
28
29#define HW_EQ_IDX(band, setting) ((void *)(((setting) << 8) | (band)))
30#define HW_EQ_IDX_BAND(data) ((uint8_t)(uintptr_t)(data))
31#define HW_EQ_IDX_SETTING(data) ((uint8_t)((uintptr_t)(data) >> 8))
32
33static unsigned short hw_eq_setting_lang_ids[AUDIOHW_EQ_SETTING_NUM] =
34{
35 LANG_HW_EQ_GAIN,
36#ifdef AUDIOHW_HAVE_EQ_FREQUENCY
37 LANG_HW_EQ_FREQUENCY,
38#endif
39#ifdef AUDIOHW_HAVE_EQ_WIDTH
40 LANG_HW_EQ_WIDTH,
41#endif
42};
43
44static char * hw_eq_get_name(int selected_item, void * data, char *buffer)
45{
46 snprintf(buffer, MAX_PATH,
47 str(hw_eq_setting_lang_ids[HW_EQ_IDX_SETTING(data)]),
48 HW_EQ_IDX_BAND(data) + 1);
49 return buffer;
50 (void)selected_item;
51}
52
53static int hw_eq_speak_item(int selected_item, void * data)
54{
55 talk_id(hw_eq_setting_lang_ids[HW_EQ_IDX_SETTING(data)], false);
56 talk_number(HW_EQ_IDX_BAND(data) + 1, true);
57 return 0;
58 (void)selected_item;
59}
60
61static int hw_eq_do_band_setting(void *param)
62{
63 int band = HW_EQ_IDX_BAND(param);
64 int setting = HW_EQ_IDX_SETTING(param);
65 char desc[MAX_PATH];
66 struct menu_callback_with_desc cbwdesc =
67 {
68 .menu_callback = NULL,
69 .desc = hw_eq_get_name(0, param, desc),
70 .icon_id = Icon_NOICON
71 };
72 struct menu_item_ex item =
73 {
74 .flags = MT_SETTING_W_TEXT | MENU_HAS_DESC,
75 { .variable = (void*)(&global_settings.hw_eq_bands[band].gain + setting) },
76 { .callback_and_desc = &cbwdesc }
77 };
78 do_setting_from_menu(&item, NULL);
79 return 0;
80}
81
82MENUITEM_FUNCTION_DYNTEXT(hw_eq_band1_gain, MENU_FUNC_USEPARAM,
83 hw_eq_do_band_setting,
84 HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_GAIN),
85 hw_eq_get_name, hw_eq_speak_item,
86 HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_GAIN),
87 NULL, Icon_Menu_setting);
88#ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
89MENUITEM_FUNCTION_DYNTEXT(hw_eq_band1_frequency, MENU_FUNC_USEPARAM,
90 hw_eq_do_band_setting,
91 HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_FREQUENCY),
92 hw_eq_get_name, hw_eq_speak_item,
93 HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_FREQUENCY),
94 NULL, Icon_NOICON);
95#endif
96#ifdef AUDIOHW_HAVE_EQ_BAND2
97MENUITEM_FUNCTION_DYNTEXT(hw_eq_band2_gain, MENU_FUNC_USEPARAM,
98 hw_eq_do_band_setting,
99 HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_GAIN),
100 hw_eq_get_name, hw_eq_speak_item,
101 HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_GAIN),
102 NULL, Icon_Menu_setting);
103#ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
104MENUITEM_FUNCTION_DYNTEXT(hw_eq_band2_frequency, MENU_FUNC_USEPARAM,
105 hw_eq_do_band_setting,
106 HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_FREQUENCY),
107 hw_eq_get_name, hw_eq_speak_item,
108 HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_FREQUENCY),
109 NULL, Icon_NOICON);
110#endif
111#ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
112MENUITEM_FUNCTION_DYNTEXT(hw_eq_band2_width, MENU_FUNC_USEPARAM,
113 hw_eq_do_band_setting,
114 HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_WIDTH),
115 hw_eq_get_name, hw_eq_speak_item,
116 HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_WIDTH),
117 NULL, Icon_NOICON);
118#endif
119#endif /* AUDIOHW_HAVE_EQ_BAND2 */
120#ifdef AUDIOHW_HAVE_EQ_BAND3
121MENUITEM_FUNCTION_DYNTEXT(hw_eq_band3_gain, MENU_FUNC_USEPARAM,
122 hw_eq_do_band_setting,
123 HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_GAIN),
124 hw_eq_get_name, hw_eq_speak_item,
125 HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_GAIN),
126 NULL, Icon_Menu_setting);
127#ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
128MENUITEM_FUNCTION_DYNTEXT(hw_eq_band3_frequency, MENU_FUNC_USEPARAM,
129 hw_eq_do_band_setting,
130 HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_FREQUENCY),
131 hw_eq_get_name, hw_eq_speak_item,
132 HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_FREQUENCY),
133 NULL, Icon_NOICON);
134#endif
135#ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
136MENUITEM_FUNCTION_DYNTEXT(hw_eq_band3_width, MENU_FUNC_USEPARAM,
137 hw_eq_do_band_setting,
138 HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_WIDTH),
139 hw_eq_get_name, hw_eq_speak_item,
140 HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_WIDTH),
141 NULL, Icon_NOICON);
142#endif
143#endif /* AUDIOHW_HAVE_EQ_BAND3 */
144#ifdef AUDIOHW_HAVE_EQ_BAND4
145MENUITEM_FUNCTION_DYNTEXT(hw_eq_band4_gain, MENU_FUNC_USEPARAM,
146 hw_eq_do_band_setting,
147 HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_GAIN),
148 hw_eq_get_name, hw_eq_speak_item,
149 HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_GAIN),
150 NULL, Icon_Menu_setting);
151#ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
152MENUITEM_FUNCTION_DYNTEXT(hw_eq_band4_frequency, MENU_FUNC_USEPARAM,
153 hw_eq_do_band_setting,
154 HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_FREQUENCY),
155 hw_eq_get_name, hw_eq_speak_item,
156 HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_FREQUENCY),
157 NULL, Icon_NOICON);
158#endif
159#ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
160MENUITEM_FUNCTION_DYNTEXT(hw_eq_band4_width, MENU_FUNC_USEPARAM,
161 hw_eq_do_band_setting,
162 HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_WIDTH),
163 hw_eq_get_name, hw_eq_speak_item,
164 HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_WIDTH),
165 NULL, Icon_NOICON);
166#endif
167#endif /* AUDIOHW_HAVE_EQ_BAND4 */
168#ifdef AUDIOHW_HAVE_EQ_BAND5
169MENUITEM_FUNCTION_DYNTEXT(hw_eq_band5_gain, MENU_FUNC_USEPARAM,
170 hw_eq_do_band_setting,
171 HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_GAIN),
172 hw_eq_get_name, hw_eq_speak_item,
173 HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_GAIN),
174 NULL, Icon_Menu_setting);
175#ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
176MENUITEM_FUNCTION_DYNTEXT(hw_eq_band5_frequency, MENU_FUNC_USEPARAM,
177 hw_eq_do_band_setting,
178 HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_FREQUENCY),
179 hw_eq_get_name, hw_eq_speak_item,
180 HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_FREQUENCY),
181 NULL, Icon_NOICON);
182#endif
183#endif /* AUDIOHW_HAVE_EQ_BAND5 */
184
185/* Submenu for multiple "tone controls". Gain + all advanced settings. */
186MAKE_MENU(hardware_eq_tone_controls_advanced, ID2P(LANG_HW_EQ_TONE_CONTROLS_ADVANCED),
187 NULL, Icon_NOICON
188 ,&hw_eq_band1_gain
189#ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
190 ,&hw_eq_band1_frequency
191#endif
192#ifdef AUDIOHW_HAVE_EQ_BAND2
193 ,&hw_eq_band2_gain
194#ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
195 ,&hw_eq_band2_frequency
196#endif
197#ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
198 ,&hw_eq_band2_width
199#endif
200#endif /* AUDIOHW_HAVE_EQ_BAND2 */
201#ifdef AUDIOHW_HAVE_EQ_BAND3
202 ,&hw_eq_band3_gain
203#ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
204 ,&hw_eq_band3_frequency
205#endif
206#ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
207 ,&hw_eq_band3_width
208#endif
209#endif /* AUDIOHW_HAVE_EQ_BAND3 */
210#ifdef AUDIOHW_HAVE_EQ_BAND4
211 ,&hw_eq_band4_gain
212#ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
213 ,&hw_eq_band4_frequency
214#endif
215#ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
216 ,&hw_eq_band4_width
217#endif
218#endif /* AUDIOHW_HAVE_EQ_BAND4 */
219#ifdef AUDIOHW_HAVE_EQ_BAND5
220 ,&hw_eq_band5_gain
221#ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
222 ,&hw_eq_band5_frequency
223#endif
224#endif /* AUDIOHW_HAVE_EQ_BAND5 */
225 );
226/* Shows only the gains + advanced settings submenu */
227MAKE_MENU(audiohw_eq_tone_controls, ID2P(LANG_HW_EQ_TONE_CONTROLS),
228 NULL, Icon_NOICON
229 ,&hw_eq_band1_gain
230#ifdef AUDIOHW_HAVE_EQ_BAND2
231 ,&hw_eq_band2_gain
232#endif
233#ifdef AUDIOHW_HAVE_EQ_BAND3
234 ,&hw_eq_band3_gain
235#endif
236#ifdef AUDIOHW_HAVE_EQ_BAND4
237 ,&hw_eq_band4_gain
238#endif
239#ifdef AUDIOHW_HAVE_EQ_BAND5
240 ,&hw_eq_band5_gain
241#endif
242 ,&hardware_eq_tone_controls_advanced
243 );
244