When we read the year from the RTC, it can be so totally messed up so that
[kugel-rb.git] / apps / sound_menu.c
blob26f37ea0e7035a0a5b87e118490535c420972865
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
20 #include <stdio.h>
21 #include <stdbool.h>
22 #include "kernel.h"
23 #include "lcd.h"
24 #include "menu.h"
25 #include "button.h"
26 #include "mpeg.h"
27 #include "settings.h"
28 #include "status.h"
29 #include "screens.h"
30 #ifdef HAVE_LCD_BITMAP
31 #include "icons.h"
32 #endif
33 #include "lang.h"
34 #include "sprintf.h"
36 static char *fmt[] =
38 "", /* no decimals */
39 "%d.%d %s ", /* 1 decimal */
40 "%d.%02d %s " /* 2 decimals */
43 bool set_sound(char* string,
44 int* variable,
45 int setting)
47 bool done = false;
48 bool changed = true;
49 int min, max;
50 int val;
51 int numdec;
52 int integer;
53 int dec;
54 char* unit;
55 char str[32];
57 unit = mpeg_sound_unit(setting);
58 numdec = mpeg_sound_numdecimals(setting);
59 min = mpeg_sound_min(setting);
60 max = mpeg_sound_max(setting);
62 #ifdef HAVE_LCD_BITMAP
63 if(global_settings.statusbar)
64 lcd_setmargins(0, STATUSBAR_HEIGHT);
65 else
66 lcd_setmargins(0, 0);
67 #endif
68 lcd_clear_display();
69 lcd_puts_scroll(0,0,string);
71 while (!done) {
72 if (changed) {
73 val = mpeg_val2phys(setting, *variable);
74 if(numdec)
76 integer = val / (10 * numdec);
77 dec = val % (10 * numdec);
78 snprintf(str,sizeof str, fmt[numdec], integer, dec, unit);
80 else
82 snprintf(str,sizeof str,"%d %s ", val, unit);
85 lcd_puts(0,1,str);
86 status_draw(true);
87 lcd_update();
89 changed = false;
90 switch( button_get_w_tmo(HZ/2) ) {
91 #ifdef HAVE_RECORDER_KEYPAD
92 case BUTTON_UP:
93 case BUTTON_UP | BUTTON_REPEAT:
94 #else
95 case BUTTON_RIGHT:
96 case BUTTON_RIGHT | BUTTON_REPEAT:
97 #endif
98 (*variable)++;
99 if(*variable > max )
100 *variable = max;
101 changed = true;
102 break;
104 #ifdef HAVE_RECORDER_KEYPAD
105 case BUTTON_DOWN:
106 case BUTTON_DOWN | BUTTON_REPEAT:
107 #else
108 case BUTTON_LEFT:
109 case BUTTON_LEFT | BUTTON_REPEAT:
110 #endif
111 (*variable)--;
112 if(*variable < min )
113 *variable = min;
114 changed = true;
115 break;
117 #ifdef HAVE_RECORDER_KEYPAD
118 case BUTTON_LEFT:
119 #else
120 case BUTTON_STOP:
121 case BUTTON_MENU:
122 #endif
123 done = true;
124 break;
126 case SYS_USB_CONNECTED:
127 usb_screen();
128 return true;
130 if (changed) {
131 mpeg_sound_set(setting, *variable);
132 #ifdef HAVE_MAS3507D
133 if(setting == SOUND_BALANCE)
134 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
135 #endif
138 lcd_stop_scroll();
139 return false;
142 static bool volume(void)
144 return set_sound(str(LANG_VOLUME), &global_settings.volume, SOUND_VOLUME);
147 static bool balance(void)
149 return set_sound(str(LANG_BALANCE), &global_settings.balance,
150 SOUND_BALANCE);
153 static bool bass(void)
155 return set_sound(str(LANG_BASS), &global_settings.bass, SOUND_BASS);
158 static bool treble(void)
160 return set_sound(str(LANG_TREBLE), &global_settings.treble, SOUND_TREBLE);
163 #ifdef HAVE_MAS3587F
164 static bool loudness(void)
166 return set_sound(str(LANG_LOUDNESS), &global_settings.loudness,
167 SOUND_LOUDNESS);
170 static bool bass_boost(void)
172 return set_sound(str(LANG_BBOOST), &global_settings.bass_boost,
173 SOUND_SUPERBASS);
176 static void set_avc(int val)
178 mpeg_sound_set(SOUND_AVC, val);
181 static bool avc(void)
183 char* names[] = { str(LANG_OFF), "2s", "4s", "8s" };
184 return set_option(str(LANG_DECAY), &global_settings.avc,
185 names, 4, set_avc);
188 static bool recsource(void)
190 char *names[] = {str(LANG_RECORDING_SRC_MIC), str(LANG_RECORDING_SRC_LINE),
191 str(LANG_RECORDING_SRC_DIGITAL) };
192 return set_option(str(LANG_RECORDING_SOURCE),
193 &global_settings.rec_source,
194 names, 3, NULL );
197 static bool recfrequency(void)
199 char *names[] = {"44.1kHz", "48kHz", "32kHz",
200 "22.05kHz", "24kHz", "16kHz"};
202 return set_option(str(LANG_RECORDING_FREQUENCY),
203 &global_settings.rec_frequency,
204 names, 6, NULL );
207 static bool recchannels(void)
209 char *names[] = {str(LANG_CHANNEL_STEREO), str(LANG_CHANNEL_MONO)};
211 return set_option(str(LANG_RECORDING_CHANNELS),
212 &global_settings.rec_channels,
213 names, 2, NULL );
216 static bool recquality(void)
218 return set_int(str(LANG_RECORDING_QUALITY), "",
219 &global_settings.rec_quality,
220 NULL, 1, 0, 7 );
223 static bool receditable(void)
225 return set_bool(str(LANG_RECORDING_EDITABLE),
226 &global_settings.rec_editable);
228 #endif /* HAVE_MAS3587F */
230 static void set_chanconf(int val)
232 mpeg_sound_set(SOUND_CHANNELS, val);
235 static bool chanconf(void)
237 char *names[] = {str(LANG_CHANNEL_STEREO),
238 #ifdef HAVE_LCD_CHARCELLS
239 str(LANG_CHANNEL_STEREO_NARROW_PLAYER),
240 #else
241 str(LANG_CHANNEL_STEREO_NARROW_RECORDER),
242 #endif
243 str(LANG_CHANNEL_MONO),
244 str(LANG_CHANNEL_LEFT), str(LANG_CHANNEL_RIGHT),
245 str(LANG_CHANNEL_KARAOKE), str(LANG_CHANNEL_STEREO_WIDE) };
246 return set_option(str(LANG_CHANNEL), &global_settings.channel_config,
247 names, 7, set_chanconf );
250 bool sound_menu(void)
252 int m;
253 bool result;
254 struct menu_items items[] = {
255 { str(LANG_VOLUME), volume },
256 { str(LANG_BASS), bass },
257 { str(LANG_TREBLE), treble },
258 { str(LANG_BALANCE), balance },
259 { str(LANG_CHANNEL_MENU), chanconf },
260 #ifdef HAVE_MAS3587F
261 { str(LANG_LOUDNESS), loudness },
262 { str(LANG_BBOOST), bass_boost },
263 { str(LANG_AUTOVOL), avc }
264 #endif
267 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
268 result = menu_run(m);
269 menu_exit(m);
271 return result;
274 #ifdef HAVE_MAS3587F
275 bool recording_menu(void)
277 int m;
278 bool result;
279 struct menu_items items[] = {
280 { str(LANG_RECORDING_QUALITY), recquality },
281 { str(LANG_RECORDING_FREQUENCY), recfrequency },
282 { str(LANG_RECORDING_SOURCE), recsource },
283 { str(LANG_RECORDING_CHANNELS), recchannels },
284 { str(LANG_RECORDING_EDITABLE), receditable },
287 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
288 result = menu_run(m);
289 menu_exit(m);
291 return result;
293 #endif