summaryrefslogtreecommitdiffstats
path: root/apps/menus/audiohw_eq_menu.c
blob: 8dfb6e84501769725137ff3b28544c01561c8ba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2010 Michael Sevakis
 *
 * 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.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include <stdio.h>
#include "config.h"
#include "sound.h"
#include "settings.h"
#include "lang.h"
#include "menu.h"
#include "talk.h"

#define HW_EQ_IDX(band, setting)  ((void *)(((setting) << 8) | (band)))
#define HW_EQ_IDX_BAND(data)      ((uint8_t)(uintptr_t)(data))
#define HW_EQ_IDX_SETTING(data)   ((uint8_t)((uintptr_t)(data) >> 8))

static unsigned short hw_eq_setting_lang_ids[AUDIOHW_EQ_SETTING_NUM] =
{
    LANG_HW_EQ_GAIN,
#ifdef AUDIOHW_HAVE_EQ_FREQUENCY
    LANG_HW_EQ_FREQUENCY,
#endif
#ifdef AUDIOHW_HAVE_EQ_WIDTH
    LANG_HW_EQ_WIDTH,
#endif
};

static char * hw_eq_get_name(int selected_item, void * data,
                             char *buffer, size_t buffer_len)
{
    snprintf(buffer, buffer_len,
             str(hw_eq_setting_lang_ids[HW_EQ_IDX_SETTING(data)]),
             HW_EQ_IDX_BAND(data) + 1);
    return buffer;
    (void)selected_item;
}

static int hw_eq_speak_item(int selected_item, void * data)
{
    talk_id(hw_eq_setting_lang_ids[HW_EQ_IDX_SETTING(data)], false);
    talk_number(HW_EQ_IDX_BAND(data) + 1, true);
    return 0;
    (void)selected_item;
}

static int hw_eq_do_band_setting(void *param)
{
    int band = HW_EQ_IDX_BAND(param);
    int setting = HW_EQ_IDX_SETTING(param);
    char desc[MAX_PATH];
    struct menu_callback_with_desc cbwdesc =
    {
        .menu_callback = NULL,
        .desc = hw_eq_get_name(0, param, desc),
        .icon_id = Icon_NOICON
    };
    struct menu_item_ex item =
    {
        .flags = MT_SETTING_W_TEXT | MENU_HAS_DESC,
        { .variable = (void*)(&global_settings.hw_eq_bands[band].gain + setting) },
        { .callback_and_desc = &cbwdesc }
    };
    do_setting_from_menu(&item, NULL);
    return 0;
}

MENUITEM_FUNCTION_DYNTEXT(hw_eq_band1_gain, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_GAIN),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_GAIN),
                          NULL, Icon_Menu_setting);
#ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band1_frequency, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_FREQUENCY),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND1, AUDIOHW_EQ_FREQUENCY),
                          NULL, Icon_NOICON);
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND2
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band2_gain, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_GAIN),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_GAIN),
                          NULL, Icon_Menu_setting);
#ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band2_frequency, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_FREQUENCY),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_FREQUENCY),
                          NULL, Icon_NOICON);
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band2_width, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_WIDTH),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND2, AUDIOHW_EQ_WIDTH),
                          NULL, Icon_NOICON);
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND2 */
#ifdef AUDIOHW_HAVE_EQ_BAND3
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band3_gain, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_GAIN),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_GAIN),
                          NULL, Icon_Menu_setting);
#ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band3_frequency, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_FREQUENCY),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_FREQUENCY),
                          NULL, Icon_NOICON);
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band3_width, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_WIDTH),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND3, AUDIOHW_EQ_WIDTH),
                          NULL, Icon_NOICON);
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND3 */
#ifdef AUDIOHW_HAVE_EQ_BAND4
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band4_gain, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_GAIN),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_GAIN),
                          NULL, Icon_Menu_setting);
#ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band4_frequency, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_FREQUENCY),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_FREQUENCY),
                          NULL, Icon_NOICON);
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band4_width, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_WIDTH),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND4, AUDIOHW_EQ_WIDTH),
                          NULL, Icon_NOICON);
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND4 */
#ifdef AUDIOHW_HAVE_EQ_BAND5
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band5_gain, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_GAIN),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_GAIN),
                          NULL, Icon_Menu_setting);
#ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
MENUITEM_FUNCTION_DYNTEXT(hw_eq_band5_frequency, MENU_FUNC_USEPARAM,
                          hw_eq_do_band_setting,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_FREQUENCY),
                          hw_eq_get_name, hw_eq_speak_item,
                          HW_EQ_IDX(AUDIOHW_EQ_BAND5, AUDIOHW_EQ_FREQUENCY),
                          NULL, Icon_NOICON);
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND5 */

/* Submenu for multiple "tone controls". Gain + all advanced settings. */
MAKE_MENU(hardware_eq_tone_controls_advanced, ID2P(LANG_HW_EQ_TONE_CONTROLS_ADVANCED),
          NULL, Icon_NOICON
          ,&hw_eq_band1_gain
#ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
          ,&hw_eq_band1_frequency
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND2
          ,&hw_eq_band2_gain
#ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
          ,&hw_eq_band2_frequency
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
          ,&hw_eq_band2_width
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND2 */
#ifdef AUDIOHW_HAVE_EQ_BAND3
          ,&hw_eq_band3_gain
#ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
          ,&hw_eq_band3_frequency
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
          ,&hw_eq_band3_width
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND3 */
#ifdef AUDIOHW_HAVE_EQ_BAND4
          ,&hw_eq_band4_gain
#ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
          ,&hw_eq_band4_frequency
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
          ,&hw_eq_band4_width
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND4 */
#ifdef AUDIOHW_HAVE_EQ_BAND5
          ,&hw_eq_band5_gain
#ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
          ,&hw_eq_band5_frequency
#endif
#endif /* AUDIOHW_HAVE_EQ_BAND5 */
    );
/* Shows only the gains + advanced settings submenu */
MAKE_MENU(audiohw_eq_tone_controls, ID2P(LANG_HW_EQ_TONE_CONTROLS),
          NULL, Icon_NOICON
          ,&hw_eq_band1_gain
#ifdef AUDIOHW_HAVE_EQ_BAND2
          ,&hw_eq_band2_gain
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND3
          ,&hw_eq_band3_gain
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND4
          ,&hw_eq_band4_gain
#endif
#ifdef AUDIOHW_HAVE_EQ_BAND5
          ,&hw_eq_band5_gain
#endif
          ,&hardware_eq_tone_controls_advanced
    );