Windows requires setting files to binary mode
[kugel-rb.git] / apps / sound_menu.c
blob6e5b74bfa3809731ae6d73af9bff1ccb6dd3a580
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 "mp3_playback.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"
35 #include "talk.h"
36 #include "misc.h"
38 static const char* const fmt[] =
40 "", /* no decimals */
41 "%d.%d %s ", /* 1 decimal */
42 "%d.%02d %s " /* 2 decimals */
45 bool set_sound(const char* string,
46 int* variable,
47 int setting)
49 bool done = false;
50 bool changed = true;
51 int min, max;
52 int val;
53 int numdec;
54 int integer;
55 int dec;
56 const char* unit;
57 char str[32];
58 int talkunit = UNIT_INT;
59 int steps;
60 int button;
62 unit = mpeg_sound_unit(setting);
63 numdec = mpeg_sound_numdecimals(setting);
64 steps = mpeg_sound_steps(setting);
65 min = mpeg_sound_min(setting);
66 max = mpeg_sound_max(setting);
67 if (*unit == 'd') /* crude reconstruction */
68 talkunit = UNIT_DB;
69 else if (*unit == '%')
70 talkunit = UNIT_PERCENT;
71 else if (*unit == 'H')
72 talkunit = UNIT_HERTZ;
74 #ifdef HAVE_LCD_BITMAP
75 if(global_settings.statusbar)
76 lcd_setmargins(0, STATUSBAR_HEIGHT);
77 else
78 lcd_setmargins(0, 0);
79 #endif
80 lcd_clear_display();
81 lcd_puts_scroll(0,0,string);
83 while (!done) {
84 if (changed) {
85 val = mpeg_val2phys(setting, *variable);
86 if(numdec)
88 integer = val / (10 * numdec);
89 dec = val % (10 * numdec);
90 snprintf(str,sizeof str, fmt[numdec], integer, dec, unit);
92 else
94 snprintf(str,sizeof str,"%d %s ", val, unit);
96 if (global_settings.talk_menu)
97 talk_value(val, talkunit, false); /* speak it */
99 lcd_puts(0,1,str);
100 status_draw(true);
101 lcd_update();
103 changed = false;
104 button = button_get_w_tmo(HZ/2);
105 switch( button ) {
106 case SETTINGS_INC:
107 case SETTINGS_INC | BUTTON_REPEAT:
108 (*variable)+=steps;
109 if(*variable > max )
110 *variable = max;
111 changed = true;
112 break;
114 case SETTINGS_DEC:
115 case SETTINGS_DEC | BUTTON_REPEAT:
116 (*variable)-=steps;
117 if(*variable < min )
118 *variable = min;
119 changed = true;
120 break;
122 case SETTINGS_OK:
123 case SETTINGS_CANCEL:
124 #ifdef SETTINGS_OK2
125 case SETTINGS_OK2:
126 #endif
127 #ifdef SETTINGS_CANCEL2
128 case SETTINGS_CANCEL2:
129 #endif
130 done = true;
131 break;
133 default:
134 if(default_event_handler(button) == SYS_USB_CONNECTED)
135 return true;
136 break;
138 if (changed) {
139 mpeg_sound_set(setting, *variable);
140 #if CONFIG_HWCODEC == MAS3507D
141 if(setting == SOUND_BALANCE)
142 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
143 #endif
146 lcd_stop_scroll();
147 return false;
150 static bool volume(void)
152 return set_sound(str(LANG_VOLUME), &global_settings.volume, SOUND_VOLUME);
155 static bool balance(void)
157 return set_sound(str(LANG_BALANCE), &global_settings.balance,
158 SOUND_BALANCE);
161 static bool bass(void)
163 return set_sound(str(LANG_BASS), &global_settings.bass, SOUND_BASS);
166 static bool treble(void)
168 return set_sound(str(LANG_TREBLE), &global_settings.treble, SOUND_TREBLE);
171 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
172 static bool loudness(void)
174 return set_sound(str(LANG_LOUDNESS), &global_settings.loudness,
175 SOUND_LOUDNESS);
178 static bool mdb_strength(void)
180 return set_sound(str(LANG_MDB_STRENGTH), &global_settings.mdb_strength,
181 SOUND_MDB_STRENGTH);
184 static bool mdb_harmonics(void)
186 return set_sound(str(LANG_MDB_HARMONICS), &global_settings.mdb_harmonics,
187 SOUND_MDB_HARMONICS);
190 static bool mdb_center(void)
192 return set_sound(str(LANG_MDB_CENTER), &global_settings.mdb_center,
193 SOUND_MDB_CENTER);
196 static bool mdb_shape(void)
198 return set_sound(str(LANG_MDB_SHAPE), &global_settings.mdb_shape,
199 SOUND_MDB_SHAPE);
202 static void set_mdb_enable(bool value)
204 mpeg_sound_set(SOUND_MDB_ENABLE, (int)value);
207 static bool mdb_enable(void)
209 return set_bool_options(str(LANG_MDB_ENABLE),
210 &global_settings.mdb_enable,
211 STR(LANG_SET_BOOL_YES),
212 STR(LANG_SET_BOOL_NO),
213 set_mdb_enable);
216 static void set_superbass(bool value)
218 mpeg_sound_set(SOUND_SUPERBASS, (int)value);
221 static bool superbass(void)
223 return set_bool_options(str(LANG_SUPERBASS),
224 &global_settings.superbass,
225 STR(LANG_SET_BOOL_YES),
226 STR(LANG_SET_BOOL_NO),
227 set_superbass);
230 static void set_avc(int val)
232 mpeg_sound_set(SOUND_AVC, val);
235 static bool avc(void)
237 static const struct opt_items names[] = {
238 { STR(LANG_OFF) },
239 { "20ms", TALK_ID(20, UNIT_MS) },
240 { "2s", TALK_ID(2, UNIT_SEC) },
241 { "4s", TALK_ID(4, UNIT_SEC) },
242 { "8s", TALK_ID(8, UNIT_SEC) }
244 return set_option(str(LANG_DECAY), &global_settings.avc, INT,
245 names, 5, set_avc);
247 #endif
249 #if CONFIG_HWCODEC == MAS3587F
250 static bool recsource(void)
252 static const struct opt_items names[] = {
253 { STR(LANG_RECORDING_SRC_MIC) },
254 { STR(LANG_RECORDING_SRC_LINE) },
255 { STR(LANG_RECORDING_SRC_DIGITAL) }
257 return set_option(str(LANG_RECORDING_SOURCE),
258 &global_settings.rec_source, INT,
259 names, 3, NULL );
262 static bool recfrequency(void)
264 static const struct opt_items names[] = {
265 { "44.1kHz", TALK_ID(44, UNIT_KHZ) },
266 { "48kHz", TALK_ID(48, UNIT_KHZ) },
267 { "32kHz", TALK_ID(32, UNIT_KHZ) },
268 { "22.05kHz", TALK_ID(22, UNIT_KHZ) },
269 { "24kHz", TALK_ID(24, UNIT_KHZ) },
270 { "16kHz", TALK_ID(16, UNIT_KHZ) }
272 return set_option(str(LANG_RECORDING_FREQUENCY),
273 &global_settings.rec_frequency, INT,
274 names, 6, NULL );
277 static bool recchannels(void)
279 static const struct opt_items names[] = {
280 { STR(LANG_CHANNEL_STEREO) },
281 { STR(LANG_CHANNEL_MONO) }
283 return set_option(str(LANG_RECORDING_CHANNELS),
284 &global_settings.rec_channels, INT,
285 names, 2, NULL );
288 static bool recquality(void)
290 return set_int(str(LANG_RECORDING_QUALITY), "", UNIT_INT,
291 &global_settings.rec_quality,
292 NULL, 1, 0, 7 );
295 static bool receditable(void)
297 return set_bool(str(LANG_RECORDING_EDITABLE),
298 &global_settings.rec_editable);
301 static bool rectimesplit(void)
303 static const struct opt_items names[] = {
304 { STR(LANG_OFF) },
305 { "00:05" , TALK_ID(5, UNIT_MIN) },
306 { "00:10" , TALK_ID(10, UNIT_MIN) },
307 { "00:15" , TALK_ID(15, UNIT_MIN) },
308 { "00:30" , TALK_ID(30, UNIT_MIN) },
309 { "01:00" , TALK_ID(1, UNIT_HOUR) },
310 { "01:14" , TALK_ID(74, UNIT_MIN) },
311 { "01:20" , TALK_ID(80, UNIT_MIN) },
312 { "02:00" , TALK_ID(2, UNIT_HOUR) },
313 { "04:00" , TALK_ID(4, UNIT_HOUR) },
314 { "06:00" , TALK_ID(6, UNIT_HOUR) },
315 { "08:00" , TALK_ID(8, UNIT_HOUR) },
316 { "10:00" , TALK_ID(10, UNIT_HOUR) },
317 { "12:00" , TALK_ID(12, UNIT_HOUR) },
318 { "18:00" , TALK_ID(18, UNIT_HOUR) },
319 { "24:00" , TALK_ID(24, UNIT_HOUR) }
321 return set_option(str(LANG_RECORD_TIMESPLIT),
322 &global_settings.rec_timesplit, INT,
323 names, 16, NULL );
326 static bool recprerecord(void)
328 static const struct opt_items names[] = {
329 { STR(LANG_OFF) },
330 { "1s", TALK_ID(1, UNIT_SEC) },
331 { "2s", TALK_ID(2, UNIT_SEC) },
332 { "3s", TALK_ID(3, UNIT_SEC) },
333 { "4s", TALK_ID(4, UNIT_SEC) },
334 { "5s", TALK_ID(5, UNIT_SEC) },
335 { "6s", TALK_ID(6, UNIT_SEC) },
336 { "7s", TALK_ID(7, UNIT_SEC) },
337 { "8s", TALK_ID(8, UNIT_SEC) },
338 { "9s", TALK_ID(9, UNIT_SEC) },
339 { "10s", TALK_ID(10, UNIT_SEC) },
340 { "11s", TALK_ID(11, UNIT_SEC) },
341 { "12s", TALK_ID(12, UNIT_SEC) },
342 { "13s", TALK_ID(13, UNIT_SEC) },
343 { "14s", TALK_ID(14, UNIT_SEC) },
344 { "15s", TALK_ID(15, UNIT_SEC) },
345 { "16s", TALK_ID(16, UNIT_SEC) },
346 { "17s", TALK_ID(17, UNIT_SEC) },
347 { "18s", TALK_ID(18, UNIT_SEC) },
348 { "19s", TALK_ID(19, UNIT_SEC) },
349 { "20s", TALK_ID(20, UNIT_SEC) },
350 { "21s", TALK_ID(21, UNIT_SEC) },
351 { "22s", TALK_ID(22, UNIT_SEC) },
352 { "23s", TALK_ID(23, UNIT_SEC) },
353 { "24s", TALK_ID(24, UNIT_SEC) },
354 { "25s", TALK_ID(25, UNIT_SEC) },
355 { "26s", TALK_ID(26, UNIT_SEC) },
356 { "27s", TALK_ID(27, UNIT_SEC) },
357 { "28s", TALK_ID(28, UNIT_SEC) },
358 { "29s", TALK_ID(29, UNIT_SEC) },
359 { "30s", TALK_ID(30, UNIT_SEC) }
361 return set_option(str(LANG_RECORD_PRERECORD_TIME),
362 &global_settings.rec_prerecord_time, INT,
363 names, 31, NULL );
366 static bool recdirectory(void)
368 static const struct opt_items names[] = {
369 { rec_base_directory, -1 },
370 { STR(LANG_RECORD_CURRENT_DIR) }
372 return set_option(str(LANG_RECORD_DIRECTORY),
373 &global_settings.rec_directory, INT,
374 names, 2, NULL );
377 #endif /* MAS3587F */
379 static void set_chanconf(int val)
381 mpeg_sound_set(SOUND_CHANNELS, val);
384 static bool chanconf(void)
386 static const struct opt_items names[] = {
387 { STR(LANG_CHANNEL_STEREO) },
388 { STR(LANG_CHANNEL_MONO) },
389 { STR(LANG_CHANNEL_CUSTOM) },
390 { STR(LANG_CHANNEL_LEFT) },
391 { STR(LANG_CHANNEL_RIGHT) },
392 { STR(LANG_CHANNEL_KARAOKE) }
394 return set_option(str(LANG_CHANNEL), &global_settings.channel_config, INT,
395 names, 6, set_chanconf );
398 static bool stereo_width(void)
400 return set_sound(str(LANG_STEREO_WIDTH), &global_settings.stereo_width,
401 SOUND_STEREO_WIDTH);
404 bool sound_menu(void)
406 int m;
407 bool result;
408 static const struct menu_item items[] = {
409 { ID2P(LANG_VOLUME), volume },
410 { ID2P(LANG_BASS), bass },
411 { ID2P(LANG_TREBLE), treble },
412 { ID2P(LANG_BALANCE), balance },
413 { ID2P(LANG_CHANNEL_MENU), chanconf },
414 { ID2P(LANG_STEREO_WIDTH), stereo_width },
415 #if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
416 { ID2P(LANG_LOUDNESS), loudness },
417 { ID2P(LANG_AUTOVOL), avc },
418 { ID2P(LANG_SUPERBASS), superbass },
419 { ID2P(LANG_MDB_ENABLE), mdb_enable },
420 { ID2P(LANG_MDB_STRENGTH), mdb_strength },
421 { ID2P(LANG_MDB_HARMONICS), mdb_harmonics },
422 { ID2P(LANG_MDB_CENTER), mdb_center },
423 { ID2P(LANG_MDB_SHAPE), mdb_shape },
424 #endif
427 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
428 NULL, NULL, NULL);
429 result = menu_run(m);
430 menu_exit(m);
432 return result;
435 #if CONFIG_HWCODEC == MAS3587F
436 bool recording_menu(bool no_source)
438 int m;
439 int i = 0;
440 struct menu_item items[8];
441 bool result;
443 items[i].desc = ID2P(LANG_RECORDING_QUALITY);
444 items[i++].function = recquality;
445 items[i].desc = ID2P(LANG_RECORDING_FREQUENCY);
446 items[i++].function = recfrequency;
447 if(!no_source) {
448 items[i].desc = ID2P(LANG_RECORDING_SOURCE);
449 items[i++].function = recsource;
451 items[i].desc = ID2P(LANG_RECORDING_CHANNELS);
452 items[i++].function = recchannels;
453 items[i].desc = ID2P(LANG_RECORDING_EDITABLE);
454 items[i++].function = receditable;
455 items[i].desc = ID2P(LANG_RECORD_TIMESPLIT);
456 items[i++].function = rectimesplit;
457 items[i].desc = ID2P(LANG_RECORD_PRERECORD_TIME);
458 items[i++].function = recprerecord;
459 items[i].desc = ID2P(LANG_RECORD_DIRECTORY);
460 items[i++].function = recdirectory;
462 m=menu_init( items, i, NULL, NULL, NULL, NULL);
463 result = menu_run(m);
464 menu_exit(m);
466 return result;
468 #endif