* removed some more unused stuff in the simulator makefile
[kugel-rb.git] / apps / sound_menu.c
blob23d4c811a531c4a1b28a2ec9772c19e789ecc816
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"
37 static char *fmt[] =
39 "", /* no decimals */
40 "%d.%d %s ", /* 1 decimal */
41 "%d.%02d %s " /* 2 decimals */
44 bool set_sound(char* string,
45 int* variable,
46 int setting)
48 bool done = false;
49 bool changed = true;
50 int min, max;
51 int val;
52 int numdec;
53 int integer;
54 int dec;
55 char* unit;
56 char str[32];
57 int talkunit = UNIT_INT;
59 unit = mpeg_sound_unit(setting);
60 numdec = mpeg_sound_numdecimals(setting);
61 min = mpeg_sound_min(setting);
62 max = mpeg_sound_max(setting);
63 if (*unit == 'd') /* crude reconstruction */
64 talkunit = UNIT_DB;
65 else if (*unit == '%')
66 talkunit = UNIT_PERCENT;
68 #ifdef HAVE_LCD_BITMAP
69 if(global_settings.statusbar)
70 lcd_setmargins(0, STATUSBAR_HEIGHT);
71 else
72 lcd_setmargins(0, 0);
73 #endif
74 lcd_clear_display();
75 lcd_puts_scroll(0,0,string);
77 while (!done) {
78 if (changed) {
79 val = mpeg_val2phys(setting, *variable);
80 if(numdec)
82 integer = val / (10 * numdec);
83 dec = val % (10 * numdec);
84 snprintf(str,sizeof str, fmt[numdec], integer, dec, unit);
86 else
88 snprintf(str,sizeof str,"%d %s ", val, unit);
90 if (global_settings.talk_menu)
91 talk_value(val, talkunit, false); /* speak it */
93 lcd_puts(0,1,str);
94 status_draw(true);
95 lcd_update();
97 changed = false;
98 switch( button_get_w_tmo(HZ/2) ) {
99 #ifdef HAVE_RECORDER_KEYPAD
100 case BUTTON_UP:
101 case BUTTON_UP | BUTTON_REPEAT:
102 #else
103 case BUTTON_RIGHT:
104 case BUTTON_RIGHT | BUTTON_REPEAT:
105 #endif
106 (*variable)++;
107 if(*variable > max )
108 *variable = max;
109 changed = true;
110 break;
112 #ifdef HAVE_RECORDER_KEYPAD
113 case BUTTON_DOWN:
114 case BUTTON_DOWN | BUTTON_REPEAT:
115 #else
116 case BUTTON_LEFT:
117 case BUTTON_LEFT | BUTTON_REPEAT:
118 #endif
119 (*variable)--;
120 if(*variable < min )
121 *variable = min;
122 changed = true;
123 break;
125 #ifdef HAVE_RECORDER_KEYPAD
126 case BUTTON_LEFT:
127 #else
128 case BUTTON_STOP:
129 case BUTTON_MENU:
130 case BUTTON_PLAY:
131 #endif
132 done = true;
133 break;
135 case SYS_USB_CONNECTED:
136 usb_screen();
137 return true;
139 if (changed) {
140 mpeg_sound_set(setting, *variable);
141 #ifdef HAVE_MAS3507D
142 if(setting == SOUND_BALANCE)
143 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
144 #endif
147 lcd_stop_scroll();
148 return false;
151 static bool volume(void)
153 return set_sound(str(LANG_VOLUME), &global_settings.volume, SOUND_VOLUME);
156 static bool balance(void)
158 return set_sound(str(LANG_BALANCE), &global_settings.balance,
159 SOUND_BALANCE);
162 static bool bass(void)
164 return set_sound(str(LANG_BASS), &global_settings.bass, SOUND_BASS);
167 static bool treble(void)
169 return set_sound(str(LANG_TREBLE), &global_settings.treble, SOUND_TREBLE);
172 #ifdef HAVE_MAS3587F
173 static bool loudness(void)
175 return set_sound(str(LANG_LOUDNESS), &global_settings.loudness,
176 SOUND_LOUDNESS);
179 static bool bass_boost(void)
181 return set_sound(str(LANG_BBOOST), &global_settings.bass_boost,
182 SOUND_SUPERBASS);
185 static void set_avc(int val)
187 mpeg_sound_set(SOUND_AVC, val);
190 static bool avc(void)
192 struct opt_items names[] = {
193 { STR(LANG_OFF) },
194 { "2s", TALK_ID(2, UNIT_SEC) },
195 { "4s", TALK_ID(4, UNIT_SEC) },
196 { "8s", TALK_ID(8, UNIT_SEC) }
198 return set_option(str(LANG_DECAY), &global_settings.avc, INT,
199 names, 4, set_avc);
202 static bool recsource(void)
204 struct opt_items names[] = {
205 { STR(LANG_RECORDING_SRC_MIC) },
206 { STR(LANG_RECORDING_SRC_LINE) },
207 { STR(LANG_RECORDING_SRC_DIGITAL) }
209 return set_option(str(LANG_RECORDING_SOURCE),
210 &global_settings.rec_source, INT,
211 names, 3, NULL );
214 static bool recfrequency(void)
216 struct opt_items names[] = {
217 { "44.1kHz", TALK_ID(44, UNIT_KHZ) },
218 { "48kHz", TALK_ID(48, UNIT_KHZ) },
219 { "32kHz", TALK_ID(32, UNIT_KHZ) },
220 { "22.05kHz", TALK_ID(22, UNIT_KHZ) },
221 { "24kHz", TALK_ID(24, UNIT_KHZ) },
222 { "16kHz", TALK_ID(16, UNIT_KHZ) }
224 return set_option(str(LANG_RECORDING_FREQUENCY),
225 &global_settings.rec_frequency, INT,
226 names, 6, NULL );
229 static bool recchannels(void)
231 struct opt_items names[] = {
232 { STR(LANG_CHANNEL_STEREO) },
233 { STR(LANG_CHANNEL_MONO) }
235 return set_option(str(LANG_RECORDING_CHANNELS),
236 &global_settings.rec_channels, INT,
237 names, 2, NULL );
240 static bool recquality(void)
242 return set_int(str(LANG_RECORDING_QUALITY), "", UNIT_INT,
243 &global_settings.rec_quality,
244 NULL, 1, 0, 7 );
247 static bool receditable(void)
249 return set_bool(str(LANG_RECORDING_EDITABLE),
250 &global_settings.rec_editable);
253 static bool rectimesplit(void)
255 struct opt_items names[] = {
256 { STR(LANG_OFF) },
257 { "00:05" , TALK_ID(5, UNIT_MIN) },
258 { "00:10" , TALK_ID(10, UNIT_MIN) },
259 { "00:15" , TALK_ID(15, UNIT_MIN) },
260 { "00:30" , TALK_ID(30, UNIT_MIN) },
261 { "01:00" , TALK_ID(1, UNIT_HOUR) },
262 { "02:00" , TALK_ID(2, UNIT_HOUR) },
263 { "04:00" , TALK_ID(4, UNIT_HOUR) },
264 { "06:00" , TALK_ID(6, UNIT_HOUR) },
265 { "08:00" , TALK_ID(8, UNIT_HOUR) },
266 { "10:00" , TALK_ID(10, UNIT_HOUR) },
267 { "12:00" , TALK_ID(12, UNIT_HOUR) },
268 { "18:00" , TALK_ID(18, UNIT_HOUR) },
269 { "24:00" , TALK_ID(24, UNIT_HOUR) }
271 return set_option(str(LANG_RECORD_TIMESPLIT),
272 &global_settings.rec_timesplit, INT,
273 names, 14, NULL );
276 static bool recprerecord(void)
278 struct opt_items names[] = {
279 { STR(LANG_OFF) },
280 { "1s", TALK_ID(1, UNIT_SEC) },
281 { "2s", TALK_ID(2, UNIT_SEC) },
282 { "3s", TALK_ID(3, UNIT_SEC) },
283 { "4s", TALK_ID(4, UNIT_SEC) },
284 { "5s", TALK_ID(5, UNIT_SEC) },
285 { "6s", TALK_ID(6, UNIT_SEC) },
286 { "7s", TALK_ID(7, UNIT_SEC) },
287 { "8s", TALK_ID(8, UNIT_SEC) },
288 { "9s", TALK_ID(9, UNIT_SEC) },
289 { "10s", TALK_ID(10, UNIT_SEC) },
290 { "11s", TALK_ID(11, UNIT_SEC) },
291 { "12s", TALK_ID(12, UNIT_SEC) },
292 { "13s", TALK_ID(13, UNIT_SEC) },
293 { "14s", TALK_ID(14, UNIT_SEC) },
294 { "15s", TALK_ID(15, UNIT_SEC) },
295 { "16s", TALK_ID(16, UNIT_SEC) },
296 { "17s", TALK_ID(17, UNIT_SEC) },
297 { "18s", TALK_ID(18, UNIT_SEC) },
298 { "19s", TALK_ID(19, UNIT_SEC) },
299 { "20s", TALK_ID(20, UNIT_SEC) },
300 { "21s", TALK_ID(21, UNIT_SEC) },
301 { "22s", TALK_ID(22, UNIT_SEC) },
302 { "23s", TALK_ID(23, UNIT_SEC) },
303 { "24s", TALK_ID(24, UNIT_SEC) },
304 { "25s", TALK_ID(25, UNIT_SEC) },
305 { "26s", TALK_ID(26, UNIT_SEC) },
306 { "27s", TALK_ID(27, UNIT_SEC) },
307 { "28s", TALK_ID(28, UNIT_SEC) },
308 { "29s", TALK_ID(29, UNIT_SEC) },
309 { "30s", TALK_ID(30, UNIT_SEC) }
311 return set_option(str(LANG_RECORD_PRERECORD_TIME),
312 &global_settings.rec_prerecord_time, INT,
313 names, 31, NULL );
316 static bool recdirectory(void)
318 struct opt_items names[] = {
319 { rec_base_directory, -1 },
320 { STR(LANG_RECORD_CURRENT_DIR) }
322 return set_option(str(LANG_RECORD_DIRECTORY),
323 &global_settings.rec_directory, INT,
324 names, 2, NULL );
327 #endif /* HAVE_MAS3587F */
329 static void set_chanconf(int val)
331 mpeg_sound_set(SOUND_CHANNELS, val);
334 static bool chanconf(void)
336 struct opt_items names[] = {
337 { STR(LANG_CHANNEL_STEREO) },
338 #ifdef HAVE_LCD_CHARCELLS
339 { STR(LANG_CHANNEL_STEREO_NARROW_PLAYER) },
340 #else
341 { STR(LANG_CHANNEL_STEREO_NARROW_RECORDER) },
342 #endif
343 { STR(LANG_CHANNEL_MONO) },
344 { STR(LANG_CHANNEL_LEFT) },
345 { STR(LANG_CHANNEL_RIGHT) },
346 { STR(LANG_CHANNEL_KARAOKE) },
347 { STR(LANG_CHANNEL_STEREO_WIDE) }
349 return set_option(str(LANG_CHANNEL), &global_settings.channel_config, INT,
350 names, 7, set_chanconf );
353 bool sound_menu(void)
355 int m;
356 bool result;
357 struct menu_item items[] = {
358 { STR(LANG_VOLUME), volume },
359 { STR(LANG_BASS), bass },
360 { STR(LANG_TREBLE), treble },
361 { STR(LANG_BALANCE), balance },
362 { STR(LANG_CHANNEL_MENU), chanconf },
363 #ifdef HAVE_MAS3587F
364 { STR(LANG_LOUDNESS), loudness },
365 { STR(LANG_BBOOST), bass_boost },
366 { STR(LANG_AUTOVOL), avc }
367 #endif
370 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
371 NULL, NULL, NULL);
372 result = menu_run(m);
373 menu_exit(m);
375 return result;
378 #ifdef HAVE_MAS3587F
379 bool recording_menu(bool no_source)
381 int m;
382 int i = 0;
383 struct menu_item items[8];
384 bool result;
386 items[i].desc = str(LANG_RECORDING_QUALITY);
387 items[i].voice_id = LANG_RECORDING_QUALITY;
388 items[i++].function = recquality;
389 items[i].desc = str(LANG_RECORDING_FREQUENCY);
390 items[i].voice_id = LANG_RECORDING_FREQUENCY;
391 items[i++].function = recfrequency;
392 if(!no_source) {
393 items[i].desc = str(LANG_RECORDING_SOURCE);
394 items[i].voice_id = LANG_RECORDING_SOURCE;
395 items[i++].function = recsource;
397 items[i].desc = str(LANG_RECORDING_CHANNELS);
398 items[i].voice_id = LANG_RECORDING_CHANNELS;
399 items[i++].function = recchannels;
400 items[i].desc = str(LANG_RECORDING_EDITABLE);
401 items[i].voice_id = LANG_RECORDING_EDITABLE;
402 items[i++].function = receditable;
403 items[i].desc = str(LANG_RECORD_TIMESPLIT);
404 items[i].voice_id = LANG_RECORD_TIMESPLIT;
405 items[i++].function = rectimesplit;
406 items[i].desc = str(LANG_RECORD_PRERECORD_TIME);
407 items[i].voice_id = LANG_RECORD_PRERECORD_TIME;
408 items[i++].function = recprerecord;
409 items[i].desc = str(LANG_RECORD_DIRECTORY);
410 items[i].voice_id = LANG_RECORD_DIRECTORY;
411 items[i++].function = recdirectory;
413 m=menu_init( items, i, NULL, NULL, NULL, NULL);
414 result = menu_run(m);
415 menu_exit(m);
417 return result;
419 #endif